Skip to content

Commit

Permalink
Fix issue #3772
Browse files Browse the repository at this point in the history
  • Loading branch information
Sija authored and asterite committed Dec 26, 2016
1 parent 3512d3c commit 7e9be8a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 3 additions & 0 deletions spec/std/markdown/markdown_spec.cr
Expand Up @@ -80,6 +80,9 @@ describe Markdown do
assert_render "* Hello\nWorld", "<ul><li>Hello\nWorld</li></ul>"
assert_render "Params:\n* Foo\n* Bar", "<p>Params:</p>\n\n<ul><li>Foo</li><li>Bar</li></ul>"

assert_render "* Hello\n* World\n\n```\nHello World\n```", "<ul><li>Hello</li><li>World</li></ul>\n\n<pre><code>Hello World</code></pre>"
assert_render "1. Hello\n2. World\n\n```\nHello World\n```", "<ol><li>Hello</li><li>World</li></ol>\n\n<pre><code>Hello World</code></pre>"

assert_render "+ Hello", "<ul><li>Hello</li></ul>"
assert_render "- Hello", "<ul><li>Hello</li></ul>"

Expand Down
10 changes: 5 additions & 5 deletions src/markdown/parser.cr
Expand Up @@ -5,7 +5,7 @@ class Markdown::Parser
@lines : Array(String)

def initialize(text : String, @renderer : Renderer)
@lines = text.lines.map &.chomp
@lines = text.lines
@line = 0
end

Expand Down Expand Up @@ -210,6 +210,8 @@ class Markdown::Parser
@renderer.begin_unordered_list

while true
break unless starts_with_bullet_list_marker?(@lines[@line], prefix)

join_next_lines continue_on: nil, stop_on: UnorderedList.new(prefix)
line = @lines[@line]

Expand All @@ -223,8 +225,6 @@ class Markdown::Parser
next
end

break unless starts_with_bullet_list_marker?(line, prefix)

if line.starts_with?(" ") && previous_line_is_not_intended_and_starts_with_bullet_list_marker?(prefix)
@renderer.begin_unordered_list
end
Expand Down Expand Up @@ -253,6 +253,8 @@ class Markdown::Parser
@renderer.begin_ordered_list

while true
break unless starts_with_digits_dot? @lines[@line]

join_next_lines continue_on: nil, stop_on: :ordered_list
line = @lines[@line]

Expand All @@ -266,8 +268,6 @@ class Markdown::Parser
next
end

break unless starts_with_digits_dot? line

@renderer.begin_list_item
process_line line.byte_slice(line.index('.').not_nil! + 1)
@renderer.end_list_item
Expand Down

0 comments on commit 7e9be8a

Please sign in to comment.