Repository: kivy/kivy

Issue:
Markup ignores the last lines size.
```
from kivy.lang import Builder
from kivy.app import runTouchApp


kv = '''
Label:
    text: "Hello\\n[size=2dp]\\n[/size]"
    markup: True
    canvas:
        Color:
            rgba: .2, 0, .7, .3
        Rectangle:
            size: self.texture_size
            pos: self.width / 2. - self.texture_size[0] / 2.,\
            self.height / 2 - self.texture_size[1] / 2.
'''

runTouchApp(Builder.load_string(kv))
```



Discussion:
text_size (width) must be constrained for the issue to show.


Resolving patch:
diff --git a/kivy/core/text/markup.py b/kivy/core/text/markup.py
--- a/kivy/core/text/markup.py
+++ b/kivy/core/text/markup.py
@@ -131,7 +131,7 @@ def _pre_render(self):
         uw, uh = self.text_size
         spush = self._push_style
         spop = self._pop_style
-        options = self.options
+        opts = options = self.options
         options['_ref'] = None
         options['script'] = 'normal'
         xpad = options['padding_x']
@@ -220,8 +220,11 @@ def _pre_render(self):
                     opts, extents, True, False)
 
         if len(lines):  # remove any trailing spaces from the last line
+            old_opts = self.options
+            self.options = copy(opts)
             w, h, clipped = layout_text('', lines, (w, h), (uw, uhh),
-                copy(options), self.get_cached_extents(), True, True)
+                self.options, self.get_cached_extents(), True, True)
+            self.options = old_opts
 
         if options['shorten']:
             options['_ref'] = None  # no refs for you!
diff --git a/kivy/uix/label.py b/kivy/uix/label.py
--- a/kivy/uix/label.py
+++ b/kivy/uix/label.py
@@ -183,12 +183,16 @@ def texture_update(self, *largs):
         will be updated in this order.
         '''
         self.texture = None
-        if self._label.text.strip() == '':
+        if ((self.halign[-1] == 'y' or self.strip) and
+            self._label.text.strip() == ''):
             self.texture_size = (0, 0)
         else:
             mrkup = self._label.__class__ is CoreMarkupLabel
             if mrkup:
                 text = self._label.text
+                # we must strip here, otherwise, if the last line is empty,
+                # markup will retain the last empty line since it only strips
+                # line by line within markup
                 if self.halign[-1] == 'y' or self.strip:
                     text = text.strip()
                 self._label.text = ''.join(('[color=',
@@ -596,14 +600,14 @@ def print_it(instance, value):
     defaults to 0.
     '''
 
-    strip = BooleanProperty(True)
-    '''Whether leading and trailing spaces should be stripped from each
-    displayed line. If True, every line will start at the right or left edge,
-    depending on :attr:`halign`. If :attr:`halign` is `justify` it is
+    strip = BooleanProperty(False)
+    '''Whether leading and trailing spaces and newlines should be stripped from
+    each displayed line. If True, every line will start at the right or left
+    edge, depending on :attr:`halign`. If :attr:`halign` is `justify` it is
     implicitly True.
 
     .. versionadded:: 1.8.1
 
     :attr:`strip` is a :class:`~kivy.properties.BooleanProperty` and
-    defaults to True.
+    defaults to False.
     '''


Test patch: