summaryrefslogtreecommitdiff
path: root/lib/rdoc/markdown.rb
diff options
context:
space:
mode:
authorHartley McGuire <skipkayhil@gmail.com>2024-03-06 20:22:28 -0500
committerNobuyoshi Nakada <nobu@ruby-lang.org>2024-03-11 20:00:51 +0900
commit08961ce8e31487b31d19d4f66c6ef1aba5c7cd30 (patch)
treed878824800f2cf8d46219b50d2a297f389ecfc1b /lib/rdoc/markdown.rb
parent7a398adc2f7c9a912c542d19169b73aed4a544d0 (diff)
[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 https://github.com/ruby/rdoc/commit/8f943bbba4
Diffstat (limited to 'lib/rdoc/markdown.rb')
-rw-r--r--lib/rdoc/markdown.rb6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/rdoc/markdown.rb b/lib/rdoc/markdown.rb
index 157f2fa3fe..5c72a5f224 100644
--- a/lib/rdoc/markdown.rb
+++ b/lib/rdoc/markdown.rb
@@ -16445,12 +16445,12 @@ class RDoc::Markdown
return _tmp
end
- # DefinitionListLabel = StrChunk:label @Sp @Newline { label }
+ # DefinitionListLabel = Inline:label @Sp @Newline { label }
def _DefinitionListLabel
_save = self.pos
while true # sequence
- _tmp = apply(:_StrChunk)
+ _tmp = apply(:_Inline)
label = @result
unless _tmp
self.pos = _save
@@ -16777,7 +16777,7 @@ class RDoc::Markdown
Rules[:_TableAlign] = rule_info("TableAlign", "< /:?-+:?/ > @Sp { text.start_with?(\":\") ? (text.end_with?(\":\") ? :center : :left) : (text.end_with?(\":\") ? :right : nil) }")
Rules[:_DefinitionList] = rule_info("DefinitionList", "&{ definition_lists? } DefinitionListItem+:list { RDoc::Markup::List.new :NOTE, *list.flatten }")
Rules[:_DefinitionListItem] = rule_info("DefinitionListItem", "DefinitionListLabel+:label DefinitionListDefinition+:defns { list_items = [] list_items << RDoc::Markup::ListItem.new(label, defns.shift) list_items.concat defns.map { |defn| RDoc::Markup::ListItem.new nil, defn } unless list_items.empty? list_items }")
- Rules[:_DefinitionListLabel] = rule_info("DefinitionListLabel", "StrChunk:label @Sp @Newline { label }")
+ Rules[:_DefinitionListLabel] = rule_info("DefinitionListLabel", "Inline:label @Sp @Newline { label }")
Rules[:_DefinitionListDefinition] = rule_info("DefinitionListDefinition", "@NonindentSpace \":\" @Space Inlines:a @BlankLine+ { paragraph a }")
# :startdoc:
end