Skip to content

Commit 0a388a7

Browse files
authored
Ignore inline notes during Markdown reference parsing (#1713)
Inline notes inside reference labels can be parsed during the reference-gathering pass, before footnote ordering is initialized. `RDoc::Markdown.parse("[foo ^[note]]: /url\n")` This will crash a Markdown parser with a `NoMethodError`. This change treats inline-note creation as a no-op until note ordering exists.
1 parent b7b12c2 commit 0a388a7

3 files changed

Lines changed: 18 additions & 8 deletions

File tree

lib/rdoc/markdown.kpeg

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,10 +1236,12 @@ InlineNote = &{ notes? }
12361236
@StartList:a
12371237
( !"]" Inline:l { a << l } )+
12381238
"]"
1239-
{ ref = [:inline, @note_order.length]
1240-
@footnotes[ref] = paragraph a
1239+
{ if @note_order
1240+
ref = [:inline, @note_order.length]
1241+
@footnotes[ref] = paragraph a
12411242

1242-
note_for ref
1243+
note_for ref
1244+
end
12431245
}
12441246

12451247
Notes = ( Note | SkipBlock )*

lib/rdoc/markdown.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15478,7 +15478,7 @@ def _Note
1547815478
return _tmp
1547915479
end
1548015480

15481-
# InlineNote = &{ notes? } "^[" @StartList:a (!"]" Inline:l { a << l })+ "]" { ref = [:inline, @note_order.length] @footnotes[ref] = paragraph a note_for ref }
15481+
# InlineNote = &{ notes? } "^[" @StartList:a (!"]" Inline:l { a << l })+ "]" { if @note_order ref = [:inline, @note_order.length] @footnotes[ref] = paragraph a note_for ref end }
1548215482
def _InlineNote
1548315483

1548415484
_save = self.pos
@@ -15569,10 +15569,12 @@ def _InlineNote
1556915569
self.pos = _save
1557015570
break
1557115571
end
15572-
@result = begin; ref = [:inline, @note_order.length]
15573-
@footnotes[ref] = paragraph a
15572+
@result = begin; if @note_order
15573+
ref = [:inline, @note_order.length]
15574+
@footnotes[ref] = paragraph a
1557415575

15575-
note_for ref
15576+
note_for ref
15577+
end
1557615578
; end
1557715579
_tmp = true
1557815580
unless _tmp
@@ -16843,7 +16845,7 @@ def _DefinitionListDefinition
1684316845
Rules[:_NoteReference] = rule_info("NoteReference", "&{ notes? } RawNoteReference:ref { note_for ref }")
1684416846
Rules[:_RawNoteReference] = rule_info("RawNoteReference", "\"[^\" < (!@Newline !\"]\" .)+ > \"]\" { text }")
1684516847
Rules[:_Note] = rule_info("Note", "&{ notes? } @NonindentSpace RawNoteReference:ref \":\" @Sp @StartList:a RawNoteBlock:i { a.concat i } (&Indent RawNoteBlock:i { a.concat i })* { @footnotes[ref] = paragraph a nil }")
16846-
Rules[:_InlineNote] = rule_info("InlineNote", "&{ notes? } \"^[\" @StartList:a (!\"]\" Inline:l { a << l })+ \"]\" { ref = [:inline, @note_order.length] @footnotes[ref] = paragraph a note_for ref }")
16848+
Rules[:_InlineNote] = rule_info("InlineNote", "&{ notes? } \"^[\" @StartList:a (!\"]\" Inline:l { a << l })+ \"]\" { if @note_order ref = [:inline, @note_order.length] @footnotes[ref] = paragraph a note_for ref end }")
1684716849
Rules[:_Notes] = rule_info("Notes", "(Note | SkipBlock)*")
1684816850
Rules[:_RawNoteBlock] = rule_info("RawNoteBlock", "@StartList:a (!@BlankLine !RawNoteReference OptionallyIndentedLine:l { a << l })+ < @BlankLine* > { a << text } { a }")
1684916851
Rules[:_CodeFence] = rule_info("CodeFence", "&{ github? } Ticks3 (@Sp StrChunk:format)? @Sp @Newline? < ((!\"`\" Nonspacechar)+ | !Ticks3 /`+/ | Spacechar | @Newline)+ > Ticks3 @Sp @Newline* { verbatim = RDoc::Markup::Verbatim.new text verbatim.format = format.intern if format.instance_of?(String) verbatim }")

test/rdoc/rdoc_markdown_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,12 @@ def test_parse_note_reference_in_reference_label
10251025
assert_equal expected, doc
10261026
end
10271027

1028+
def test_parse_note_inline_in_reference_label
1029+
@parser.notes = true
1030+
1031+
assert_kind_of RDoc::Markup::Document, parse("[foo ^[note]]: /url\n")
1032+
end
1033+
10281034
def test_parse_note_no_notes
10291035
@parser.notes = false
10301036

0 commit comments

Comments
 (0)