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? }
992
992
"~~"
993
993
{ strike a.join }
994
994
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
+ }
998
1003
999
1004
Link = ExplicitLink | ReferenceLink | AutoLink
1000
1005
Original file line number Diff line number Diff line change @@ -98,7 +98,12 @@ def handle_RDOCLINK url # :nodoc:
98
98
99
99
gen_url CGI . escapeHTML ( url ) , CGI . escapeHTML ( text )
100
100
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
102
107
when /\A rdoc-[a-z]+:/
103
108
CGI . escapeHTML ( $')
104
109
end
Original file line number Diff line number Diff line change @@ -511,7 +511,7 @@ def test_parse_html_no_html
511
511
def test_parse_image
512
512
doc = parse "image "
513
513
514
- expected = doc ( para ( "image rdoc-image:path/to/image.jpg" ) )
514
+ expected = doc ( para ( "image rdoc-image:path/to/image.jpg:alt text " ) )
515
515
516
516
assert_equal expected , doc
517
517
end
@@ -523,7 +523,7 @@ def test_parse_image_link
523
523
524
524
expected =
525
525
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]' ) )
527
527
528
528
assert_equal expected , doc
529
529
end
You can’t perform that action at this time.
0 commit comments