Skip to content
Open
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
13 changes: 10 additions & 3 deletions lib/rdoc/markup/to_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,10 @@ def handle_TIDYLINK(label_part, url)
if label_part.size == 1 && String === label_part[0]
raw_label = label_part[0]

in_tidylink_label = @in_tidylink_label
@in_tidylink_label = true
special = apply_tidylink_label_special_handling(raw_label, url)
@in_tidylink_label = false
@in_tidylink_label = in_tidylink_label

if special
tag = gen_url(CGI.escapeHTML(url), special)
Expand All @@ -317,9 +318,10 @@ def handle_TIDYLINK(label_part, url)
open_tag, close_tag = tag.split(/(?=<\/a>)/, 2)
valid_tag = open_tag && close_tag
emit_inline(open_tag) if valid_tag
in_tidylink_label = @in_tidylink_label
@in_tidylink_label = true
traverse_inline_nodes(label_part)
@in_tidylink_label = false
@in_tidylink_label = in_tidylink_label
emit_inline(close_tag) if valid_tag
end

Expand Down Expand Up @@ -544,7 +546,12 @@ def accept_heading(heading)
if @pipe
@res << to_html(heading.text)
else
@res << "<a href=\"##{label}\">#{to_html(heading.text)}</a>"
# The heading text is the label of the heading's own link, so it must
# not contain links itself (nested <a> tags are invalid HTML).
@in_tidylink_label = true
text = to_html(heading.text)
@in_tidylink_label = false
@res << "<a href=\"##{label}\">#{text}</a>"
end

@res << "</h#{level}>\n"
Expand Down
15 changes: 15 additions & 0 deletions test/rdoc/markup/to_html_crossref_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ def test_convert_CROSSREF
assert_equal para("<code># :stopdoc:</code>:"), result
end

def test_convert_CROSSREF_in_heading
result = @to.convert "= C1 and EXAMPLE.md\n\nC1"

assert_equal "\n<span id=\"label-C1+and+EXAMPLE.md\" class=\"legacy-anchor\"></span>" \
"\n<h1 id=\"c1-and-examplemd\"><a href=\"#c1-and-examplemd\">C1 and EXAMPLE.md</a></h1>\n" +
para("<a href=\"C1.html\"><code>C1</code></a>"), result
end

def test_convert_CROSSREF_in_heading_after_tidylink
result = @to.convert "= {Foo}[https://example.com] C1"

assert_include result, '<a href="https://example.com">Foo</a>'
assert_not_include result, 'C1.html'
end

def test_convert_CROSSREF_backslash_in_tt
formatter = RDoc::Markup::ToHtmlCrossref.new('C9.html', @c9_b)

Expand Down