Skip to content

Commit 9eac17b

Browse files
committed
Add more tidylink label special workaround to make the diff smaller
1 parent f21b043 commit 9eac17b

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

lib/rdoc/markup/to_html.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,15 @@ def in_tidylink_label?
176176
# When a tidy link is <tt>{rdoc-image:path/to/image.jpg:alt text}[http://example.com]</tt>,
177177
# label part is normally considered RDOCLINK <tt>rdoc-image:path/to/image.jpg:alt</tt> and a text <tt>" text"</tt>
178178
# but RDoc's test code expects the whole label part to be treated as RDOCLINK only in tidy link label.
179+
# When a tidy link is <tt>{^1}[url]</tt> or <tt>{*1}[url]</tt>, the label part needs to drop leading * or ^.
179180
# TODO: reconsider this workaround.
180181

181-
def apply_tidylink_label_special_regexp_handling(label)
182-
@markup.regexp_handlings.each do |pattern, name|
183-
if (pattern =~ label) == 0
184-
# Prefix of a label matches to regexp handling, pass the whole label to it.
185-
return public_send(:"handle_regexp_#{name}", label)
186-
end
187-
end
188-
nil
182+
def apply_tidylink_label_special_handling(label, url)
183+
# ^1 *1 will be converted to just 1 in tidy link label.
184+
return label[1..] if label.match?(/\A[*^]\d+\z/)
185+
186+
# rdoc-image in label specially allows spaces in alt text.
187+
return handle_RDOCLINK(label) if label.start_with?('rdoc-image:')
189188
end
190189

191190
def handle_TIDYLINK(label_part, url)
@@ -202,10 +201,9 @@ def handle_TIDYLINK(label_part, url)
202201
raw_label = label_part[0]
203202

204203
@in_tidylink_label = true
205-
special = apply_tidylink_label_special_regexp_handling(raw_label)
204+
special = apply_tidylink_label_special_handling(raw_label, url)
206205
@in_tidylink_label = false
207206

208-
special ||= raw_label[1..] if raw_label.match?(/\A[*^]\d+\z/)
209207
if special
210208
tag = gen_url(CGI.escapeHTML(url), special)
211209
unless tag.empty?

lib/rdoc/markup/to_html_crossref.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,17 @@ def handle_TT(code)
206206
emit_inline(tt_cross_reference(code) || "<code>#{CGI.escapeHTML code}</code>")
207207
end
208208

209+
# Applies additional special handling on top of the one defined in ToHtml.
210+
# When a tidy link is <tt>{Foo}[rdoc-ref:Foo]</tt>, the label part is surrounded by <tt><code></code></tt>.
211+
# TODO: reconsider this workaround.
212+
def apply_tidylink_label_special_handling(label, url)
213+
if url == "rdoc-ref:#{label}" && cross_reference(label).include?('<code>')
214+
"<code>#{convert_string(label)}</code>"
215+
else
216+
super
217+
end
218+
end
219+
209220
def tt_cross_reference(code)
210221
return if in_tidylink_label?
211222

0 commit comments

Comments
 (0)