diff --git a/lib/rdoc/markdown.kpeg b/lib/rdoc/markdown.kpeg index 576a167457..66a4aa74fd 100644 --- a/lib/rdoc/markdown.kpeg +++ b/lib/rdoc/markdown.kpeg @@ -530,7 +530,7 @@ AtxInline = !@Newline !(@Sp /#*/ @Sp @Newline) Inline AtxStart = < /\#{1,6}/ > { text.length } -AtxHeading = AtxStart:s @Sp AtxInline+:a (@Sp /#*/ @Sp)? @Newline +AtxHeading = AtxStart:s @Spacechar+ AtxInline+:a (@Sp /#*/ @Sp)? @Newline { RDoc::Markup::Heading.new(s, a.join) } SetextHeading = SetextHeading1 | SetextHeading2 diff --git a/test/rdoc/test_rdoc_markdown.rb b/test/rdoc/test_rdoc_markdown.rb index 31d5b068f9..72587caf46 100644 --- a/test/rdoc/test_rdoc_markdown.rb +++ b/test/rdoc/test_rdoc_markdown.rb @@ -414,10 +414,23 @@ def test_parse_escape end def test_parse_heading_atx - doc = parse "# heading\n" + # CommonMark Example 62 + (1..6).each do |level| + doc = parse "#{"#" * level} heading\n" + + expected = @RM::Document.new( + @RM::Heading.new(level, "heading")) + + assert_equal expected, doc + end + + # CommonMark Example 64 + doc = parse "#5 bolt\n\n#hashtag\n" expected = @RM::Document.new( - @RM::Heading.new(1, "heading")) + para("#5 bolt"), + para("#hashtag"), + ) assert_equal expected, doc end