Skip to content

Commit 8f943bb

Browse files
committed
Allow rich definition list labels for Markdown
Previously, any sort of "rich" markup for a definition list's label would cause the Markdown parser to not recognize a definition list: ```ruby md = <<~md `one` : This is a definition md doc = RDoc::Markdown.parse(md) doc # => [doc: [para: "<code>one</code>\n: This is a definition"]] ``` This commit tweaks the grammar for Markdown definition lists so that labels can include "rich" markup such as bold (`**`), code (```), etc: ```ruby md = <<~md `one` : This is a definition md doc = RDoc::Markdown.parse(md) doc # => [doc: [list: NOTE [item: ["<code>one</code>"]; [para: "This is a definition"]]]] ``` The [PHP Markdown Extra][1] Spec does not seem to specify whether or not this should be allowed, but it is allowed in the RDoc format: ```ruby rdoc = <<~rdoc +code+:: This is a definition rdoc doc = RDoc::Markup.parse(rdoc) doc # => [doc: [list: NOTE [item: ["+code+"]; [para: "This is a definition"]]]] ``` so accepting this change increases the parity of the two formats. [1]: https://michelf.ca/projects/php-markdown/extra/#def-list
1 parent 4275958 commit 8f943bb

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/rdoc/markdown.kpeg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,7 @@ DefinitionListItem = ( DefinitionListLabel+ ):label
12371237
list_items
12381238
}
12391239

1240-
DefinitionListLabel = StrChunk:label @Sp @Newline
1240+
DefinitionListLabel = Inline:label @Sp @Newline
12411241
{ label }
12421242

12431243
DefinitionListDefinition = @NonindentSpace ":" @Space Inlines:a @BlankLine+

test/rdoc/test_rdoc_markdown.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,25 @@ def test_parse_definition_list_multi_line
305305
assert_equal expected, doc
306306
end
307307

308+
def test_parse_definition_list_rich_label
309+
doc = parse <<-MD
310+
`one`
311+
: This is a definition
312+
313+
**two**
314+
: This is another definition
315+
MD
316+
317+
expected = doc(
318+
list(:NOTE,
319+
item(%w[<code>one</code>],
320+
para("This is a definition")),
321+
item(%w[*two*],
322+
para("This is another definition"))))
323+
324+
assert_equal expected, doc
325+
end
326+
308327
def test_parse_definition_list_no
309328
@parser.definition_lists = false
310329

0 commit comments

Comments
 (0)