summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2017-06-30 23:59:46 -0600
committerGitHub <noreply@github.com>2017-06-30 23:59:46 -0600
commit8827261a8b2c0ca5afe24691a2c8c64186d92a2f (patch)
treeff4fb035d61c1a6017b42b2a7d143cd996612564
parent7ac4c7d64f50562eeb45744affe892d5b6ee4304 (diff)
substitute replacements in alt text of block image (PR #2285)
- substitute replacements in alt text of block image - improve tests for substitutions in alt text of block image
-rw-r--r--lib/asciidoctor/abstract_block.rb2
-rw-r--r--test/blocks_test.rb34
2 files changed, 21 insertions, 15 deletions
diff --git a/lib/asciidoctor/abstract_block.rb b/lib/asciidoctor/abstract_block.rb
index b3842bf7..214befeb 100644
--- a/lib/asciidoctor/abstract_block.rb
+++ b/lib/asciidoctor/abstract_block.rb
@@ -150,7 +150,7 @@ class AbstractBlock < AbstractNode
#
# Returns the [String] value of the alt attribute with XML special character substitutions applied.
def alt_text
- sub_specialchars attr('alt')
+ sub_replacements(sub_specialchars(attr 'alt'))
end
# Public: Determine whether this Block contains block content
diff --git a/test/blocks_test.rb b/test/blocks_test.rb
index 89315106..b5ba1057 100644
--- a/test/blocks_test.rb
+++ b/test/blocks_test.rb
@@ -1630,6 +1630,16 @@ image::images/tiger.png[Tiger]
assert_xpath '/*[@class="imageblock"]//img[@src="images/tiger.png"][@alt="Tiger"]', output, 1
end
+ test 'should substitute attribute references in alt text defined in image block macro' do
+ input = <<-EOS
+:alt-text: Tiger
+
+image::images/tiger.png[{alt-text}]
+ EOS
+ output = render_embedded_string input
+ assert_xpath '/*[@class="imageblock"]//img[@src="images/tiger.png"][@alt="Tiger"]', output, 1
+ end
+
test 'style attribute is dropped from image macro' do
input = <<-EOS
[style=value]
@@ -1642,22 +1652,18 @@ image::images/tiger.png[Tiger]
assert_nil img.style
end
- test 'alt text is escaped in HTML backend' do
- input = <<-EOS
-image::images/open.png[Select "File > Open"]
- EOS
-
- output = render_embedded_string input
- assert_match(/Select &quot;File &gt; Open&quot;/, output)
+ test 'should apply specialcharacters and replacement substitutions to alt text' do
+ input = 'A tiger\'s "roar" is < a bear\'s "growl"'
+ expected = 'A tiger&#8217;s &quot;roar&quot; is &lt; a bear&#8217;s &quot;growl&quot;'
+ result = render_embedded_string %(image::images/tiger-roar.png[#{input}])
+ assert_includes result, %(alt="#{expected}")
end
- test 'alt text is escaped in DocBook backend' do
- input = <<-EOS
-image::images/open.png[Select "File > Open"]
- EOS
-
- output = render_embedded_string input, :backend => :docbook
- assert_match(/Select "File &gt; Open"/, output)
+ test 'should not encode double quotes in alt text when converting to DocBook' do
+ input = 'Select "File > Open"'
+ expected = 'Select "File &gt; Open"'
+ result = render_embedded_string %(image::images/open.png[#{input}]), :backend => :docbook
+ assert_includes result, %(<phrase>#{expected}</phrase>)
end
test "can render block image with auto-generated alt text" do