Skip to content

Process crossref before tidylink #764

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

Merged
merged 1 commit into from
Apr 19, 2020
Merged
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
25 changes: 19 additions & 6 deletions lib/rdoc/markup/to_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,7 @@ def initialize options, markup = nil
@th = nil
@hard_break = "<br>\n"

# external links
@markup.add_regexp_handling(/(?:link:|https?:|mailto:|ftp:|irc:|www\.)\S+\w/,
:HYPERLINK)

add_regexp_handling_RDOCLINK
add_regexp_handling_TIDYLINK
init_regexp_handlings

init_tags
end
Expand All @@ -66,6 +61,24 @@ def initialize options, markup = nil
#
# These methods are used by regexp handling markup added by RDoc::Markup#add_regexp_handling.

##
# Adds regexp handlings.

def init_regexp_handlings
# external links
@markup.add_regexp_handling(/(?:link:|https?:|mailto:|ftp:|irc:|www\.)\S+\w/,
:HYPERLINK)
init_link_notation_regexp_handlings
end

##
# Adds regexp handlings about link notations.

def init_link_notation_regexp_handlings
add_regexp_handling_RDOCLINK
add_regexp_handling_TIDYLINK
end

def handle_RDOCLINK url # :nodoc:
case url
when /^rdoc-ref:/
Expand Down
12 changes: 10 additions & 2 deletions lib/rdoc/markup/to_html_crossref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,18 @@ def initialize(options, from_path, context, markup = nil)
@hyperlink_all = @options.hyperlink_all
@show_hash = @options.show_hash

crossref_re = @hyperlink_all ? ALL_CROSSREF_REGEXP : CROSSREF_REGEXP
@cross_reference = RDoc::CrossReference.new @context
end

def init_link_notation_regexp_handlings
add_regexp_handling_RDOCLINK

# The crossref must be linked before tidylink because Klass.method[:sym]
# will be processed as a tidylink first and will be broken.
crossref_re = @options.hyperlink_all ? ALL_CROSSREF_REGEXP : CROSSREF_REGEXP
@markup.add_regexp_handling crossref_re, :CROSSREF

@cross_reference = RDoc::CrossReference.new @context
add_regexp_handling_TIDYLINK
end

##
Expand Down
7 changes: 7 additions & 0 deletions test/rdoc/test_rdoc_markup_to_html_crossref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ def test_handle_regexp_CROSSREF_show_hash_false
REGEXP_HANDLING('#m')
end

def test_handle_regexp_CROSSREF_with_arg_looks_like_TIDYLINK
result = @to.convert 'C1.m[:sym]'

assert_equal para("<a href=\"C1.html#method-c-m\"><code>C1.m[:sym]</code></a>"), result,
'C1.m[:sym]'
end

def test_handle_regexp_HYPERLINK_rdoc
readme = @store.add_file 'README.txt'
readme.parser = RDoc::Parser::Simple
Expand Down