Skip to content

Commit 3797b70

Browse files
ybiquitouskou
andauthored
Refactor to use negative lookahead on rdoc-image parse
Co-authored-by: Sutou Kouhei <[email protected]>
1 parent 5a98946 commit 3797b70

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

lib/rdoc/markup/to_html.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,10 @@ def handle_RDOCLINK(url) # :nodoc:
9898

9999
gen_url CGI.escapeHTML(url), CGI.escapeHTML(text)
100100
when /^rdoc-image:/
101-
# Split the string after "rdoc-image:" into url and alt
102-
url_alt = $'
103-
split_pos = url_alt.index(%r{:[^/]})
104-
url = split_pos ? url_alt[0, split_pos] : url_alt
105-
alt = split_pos ? url_alt[split_pos + 1, url_alt.size] : nil
101+
# Split the string after "rdoc-image:" into url and alt.
102+
# "path/to/image.jpg:alt text" => ["path/to/image.jpg", "alt text"]
103+
# "http://example.com/path/to/image.jpg:alt text" => ["http://example.com/path/to/image.jpg", "alt text"]
104+
url, alt = $'.split(/:(?!\/)/, 2)
106105
if alt && !alt.empty?
107106
%[<img src="#{CGI.escapeHTML(url)}" alt="#{CGI.escapeHTML(alt)}">]
108107
else

0 commit comments

Comments
 (0)