mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 16:44:01 +02:00
[ruby/rdoc] 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
8f943bbba4
This commit is contained in:
parent
7a398adc2f
commit
08961ce8e3
2 changed files with 22 additions and 3 deletions
|
@ -305,6 +305,25 @@ that also extends to two lines
|
|||
assert_equal expected, doc
|
||||
end
|
||||
|
||||
def test_parse_definition_list_rich_label
|
||||
doc = parse <<-MD
|
||||
`one`
|
||||
: This is a definition
|
||||
|
||||
**two**
|
||||
: This is another definition
|
||||
MD
|
||||
|
||||
expected = doc(
|
||||
list(:NOTE,
|
||||
item(%w[<code>one</code>],
|
||||
para("This is a definition")),
|
||||
item(%w[*two*],
|
||||
para("This is another definition"))))
|
||||
|
||||
assert_equal expected, doc
|
||||
end
|
||||
|
||||
def test_parse_definition_list_no
|
||||
@parser.definition_lists = false
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue