lib/markdown: fix truncated lines in fence block.
authorAlexandre Terrasa <alexandre@moz-code.org>
Thu, 25 Sep 2014 00:54:51 +0000 (20:54 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Thu, 25 Sep 2014 01:11:41 +0000 (21:11 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

lib/markdown/markdown.nit
lib/markdown/test_markdown.nit

index 7c91ecc..f024257 100644 (file)
@@ -914,13 +914,18 @@ end
 class BlockCode
        super Block
 
+       # Number of char to skip at the beginning of the line.
+       #
+       # Block code lines start at 4 spaces.
+       protected var line_start = 4
+
        redef fun emit(v) do v.decorator.add_code(v, self)
 
        redef fun emit_lines(v) do
                var line = block.first_line
                while line != null do
                        if not line.is_empty then
-                               v.decorator.append_code(v, line.value, 4, line.value.length)
+                               v.decorator.append_code(v, line.value, line_start, line.value.length)
                        end
                        v.addn
                        line = line.next
@@ -934,6 +939,9 @@ end
 # this class is only used for typing purposes.
 class BlockFence
        super BlockCode
+
+       # Fence code lines start at 0 spaces.
+       redef var line_start = 0
 end
 
 # A markdown headline.
index c470df1..dd7fd58 100644 (file)
@@ -448,6 +448,63 @@ end tell
                assert res == exp
        end
 
+       fun test_process_code3 do
+               var test = """
+Here is an example of AppleScript:
+~~~
+tell application "Foo"
+    beep
+end tell
+
+<div class="footer">
+    &copy; 2004 Foo Corporation
+</div>
+~~~
+"""
+               var exp = """
+<p>Here is an example of AppleScript:</p>
+<pre><code>tell application "Foo"
+    beep
+end tell
+
+&lt;div class="footer"&gt;
+    &amp;copy; 2004 Foo Corporation
+&lt;/div&gt;
+</code></pre>
+"""
+               var res = test.md_to_html.write_to_string
+               assert res == exp
+       end
+
+       fun test_process_code4 do
+               var test = """
+Here is an example of AppleScript:
+```
+tell application "Foo"
+    beep
+end tell
+
+<div class="footer">
+    &copy; 2004 Foo Corporation
+</div>
+```
+"""
+               var exp = """
+<p>Here is an example of AppleScript:</p>
+<pre><code>tell application "Foo"
+    beep
+end tell
+
+&lt;div class="footer"&gt;
+    &amp;copy; 2004 Foo Corporation
+&lt;/div&gt;
+</code></pre>
+"""
+               var res = test.md_to_html.write_to_string
+               assert res == exp
+       end
+
+
        fun test_process_nesting1 do
                var test = """
 > ## This is a header.