File tree Expand file tree Collapse file tree 3 files changed +16
-6
lines changed
Expand file tree Collapse file tree 3 files changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -992,9 +992,14 @@ Strike = &{ strike? }
992992 "~~"
993993 { strike a.join }
994994
995- # TODO alt text support
996- Image = "!" ( ExplicitLink | ReferenceLink ):a
997- { "rdoc-image:#{a[/\[(.*)\]/, 1]}" }
995+ Image = "!" ExplicitLink:a
996+ {
997+ # Extract alt text and URL
998+ alt_text = a[/\{(.*?)\}/, 1] || ""
999+ url = a[/\[(.*?)\]/, 1] || ""
1000+
1001+ "rdoc-image:#{url}:#{alt_text}"
1002+ }
9981003
9991004Link = ExplicitLink | ReferenceLink | AutoLink
10001005
Original file line number Diff line number Diff line change @@ -98,7 +98,12 @@ def handle_RDOCLINK url # :nodoc:
9898
9999 gen_url CGI . escapeHTML ( url ) , CGI . escapeHTML ( text )
100100 when /^rdoc-image:/
101- %[<img src=\" #{ CGI . escapeHTML ( $') } \" >]
101+ url , alt = $'. split ( ":" , 2 ) # Split the string after "rdoc-image:" into url and alt
102+ if alt
103+ %[<img src="#{ CGI . escapeHTML ( url ) } " alt="#{ CGI . escapeHTML ( alt ) } ">]
104+ else
105+ %[<img src="#{ CGI . escapeHTML ( url ) } ">]
106+ end
102107 when /\A rdoc-[a-z]+:/
103108 CGI . escapeHTML ( $')
104109 end
Original file line number Diff line number Diff line change @@ -511,7 +511,7 @@ def test_parse_html_no_html
511511 def test_parse_image
512512 doc = parse "image "
513513
514- expected = doc ( para ( "image rdoc-image:path/to/image.jpg" ) )
514+ expected = doc ( para ( "image rdoc-image:path/to/image.jpg:alt text " ) )
515515
516516 assert_equal expected , doc
517517 end
@@ -523,7 +523,7 @@ def test_parse_image_link
523523
524524 expected =
525525 doc (
526- para ( '{rdoc-image:path/to/image.jpg}[http://example.com]' ) )
526+ para ( '{rdoc-image:path/to/image.jpg:alt text }[http://example.com]' ) )
527527
528528 assert_equal expected , doc
529529 end
You can’t perform that action at this time.
0 commit comments