Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: support multiline links #1110

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions lib/rdoc/markdown.kpeg
Original file line number Diff line number Diff line change
Expand Up @@ -993,27 +993,36 @@ Strike = &{ strike? }
{ strike a.join }

# TODO alt text support
Image = "!" ( ExplicitLink | ReferenceLink ):a
Image = "!" ( MultiLineExplicitLink | MultiLineReferenceLink ):a
{ "rdoc-image:#{a[/\[(.*)\]/, 1]}" }

Link = ExplicitLink | ReferenceLink | AutoLink
# Allow links to span multiple lines
Link = MultiLineExplicitLink | MultiLineReferenceLink | AutoLink

ReferenceLink = ReferenceLinkDouble | ReferenceLinkSingle
MultiLineReferenceLink = MultiLineReferenceLinkDouble | MultiLineReferenceLinkSingle

ReferenceLinkDouble = Label:content < Spnl > !"[]" Label:label
{ link_to content, label, text }
MultiLineReferenceLinkDouble = Label:content < Spnl > !"[]" Label:label
{ link_to content, label, text }

ReferenceLinkSingle = Label:content < (Spnl "[]")? >
{ link_to content, content, text }
MultiLineReferenceLinkSingle = Label:content < (Spnl "[]")? >
{ link_to content, content, text }

ExplicitLink = Label:l "(" @Sp Source:s Spnl Title @Sp ")"
{ "{#{l}}[#{s}]" }
MultiLineExplicitLink = Label:l "(" @Sp Source:s (Spnl | @Newline)+ Title @Sp ")"
{ "{#{l}}[#{s}]" }

# Example: Allow link labels and URLs to span multiple lines
Label = "[" ( !"^" &{ notes? } | &. &{ !notes? } )
@StartList:a
( !"]" Inline:l { a << l } | @Newline { a << "\n" } )+
"]"
{ a.join.gsub(/\s+/, ' ') }

Source = ( "<" < SourceContents > ">" | < SourceContents > )
{ text }

SourceContents = ( ( !"(" !")" !">" Nonspacechar )+ | "(" SourceContents ")")*
SourceContents = ( ( !("(" | ")" | ">" | @Newline) Nonspacechar )+ | "(" SourceContents ")")*

# Allow newlines in titles
Title = ( TitleSingle | TitleDouble | "" ):a
{ a }

Expand All @@ -1036,12 +1045,6 @@ Reference = @NonindentSpace !"[]"
nil
}

Label = "[" ( !"^" &{ notes? } | &. &{ !notes? } )
@StartList:a
( !"]" Inline:l { a << l } )*
"]"
{ a.join.gsub(/\s+/, ' ') }

RefSrc = < Nonspacechar+ > { text }

RefTitle = ( RefTitleSingle | RefTitleDouble | RefTitleParens | EmptyTitle )
Expand Down
15 changes: 15 additions & 0 deletions test/rdoc/test_rdoc_markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,21 @@ def test_parse_link_reference_implicit
assert_equal expected, doc
end

def test_parse_multiline_link
doc = parse <<-MD
This is an [example
link across
newlines](
http://example.com
)
MD

expected = doc(
para("This is an {example\nlink across\nnewlines}[http://example.com]"))

assert_equal expected, doc
end

def test_parse_list_bullet
doc = parse <<-MD
* one
Expand Down
Loading