summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2021-11-10 23:36:54 -0700
committerGitHub <noreply@github.com>2021-11-10 23:36:54 -0700
commitde9ef0a7d5dcc8a7bca9691c32eedf207ee3bf13 (patch)
treeb2faa98e48f65b028a2161b48123fa3161e622d4 /test
parentae07401b7bd8f3f27659044ff6f8f608f434621c (diff)
resolves #3656 add support for link=self to image macros (PR #4200)
Diffstat (limited to 'test')
-rw-r--r--test/blocks_test.rb37
-rw-r--r--test/substitutions_test.rb20
2 files changed, 57 insertions, 0 deletions
diff --git a/test/blocks_test.rb b/test/blocks_test.rb
index a6953d37..3e4a037d 100644
--- a/test/blocks_test.rb
+++ b/test/blocks_test.rb
@@ -2408,6 +2408,19 @@ context 'Blocks' do
refute_match(/<svg\s[^>]*style="[^>]*>/, output)
end
+ test 'should ignore link attribute if value is self and image target is inline SVG' do
+ input = <<~'EOS'
+ :imagesdir: fixtures
+
+ [%inline]
+ image::circle.svg[Tiger,100,link=self]
+ EOS
+
+ output = convert_string_to_embedded input, safe: Asciidoctor::SafeMode::SERVER, attributes: { 'docdir' => testdir }
+ assert_match(/<svg\s[^>]*width="100"[^>]*>/, output)
+ refute_match(/<a href=/, output)
+ end
+
test 'should honor percentage width for SVG image with inline option' do
input = <<~'EOS'
:imagesdir: fixtures
@@ -2617,6 +2630,17 @@ context 'Blocks' do
assert_xpath '/*[@class="imageblock"]//a[@class="image"][@href="http://en.wikipedia.org/wiki/Tiger"]/img[@src="images/tiger.png"][@alt="Tiger"]', output, 1
end
+ test 'can convert block image with link to self' do
+ input = <<~'EOS'
+ :imagesdir: img
+
+ image::tiger.png[Tiger, link=self]
+ EOS
+
+ output = convert_string_to_embedded input
+ assert_xpath '/*[@class="imageblock"]//a[@class="image"][@href="img/tiger.png"]/img[@src="img/tiger.png"][@alt="Tiger"]', output, 1
+ end
+
test 'adds rel=noopener attribute to block image with link that targets _blank window' do
input = 'image::images/tiger.png[Tiger,link=http://en.wikipedia.org/wiki/Tiger,window=_blank]'
output = convert_string_to_embedded input
@@ -2827,6 +2851,19 @@ context 'Blocks' do
assert_xpath '//img[starts-with(@src,"data:image/svg+xml;base64,")]', output, 1
end
+ test 'should link to data URI if value of link attribute is self and image is embedded' do
+ input = <<~'EOS'
+ :imagesdir: fixtures
+ :data-uri:
+
+ image::circle.svg[Tiger,100,link=self]
+ EOS
+
+ output = convert_string_to_embedded input, safe: Asciidoctor::SafeMode::SERVER, attributes: { 'docdir' => testdir }
+ assert_xpath '//img[starts-with(@src,"data:image/svg+xml;base64,")]', output, 1
+ assert_xpath '//a[starts-with(@href,"data:image/svg+xml;base64,")]', output, 1
+ end
+
test 'embeds empty base64-encoded data uri for unreadable image when data-uri attribute is set' do
input = <<~'EOS'
:data-uri:
diff --git a/test/substitutions_test.rb b/test/substitutions_test.rb
index 57c98641..9f3037a6 100644
--- a/test/substitutions_test.rb
+++ b/test/substitutions_test.rb
@@ -775,6 +775,13 @@ context 'Substitutions' do
refute_match(/<svg\s[^>]*style="[^>]*>/, result)
end
+ test 'should ignore link attribute if value is self and image target is inline SVG' do
+ para = block_from_string 'image:circle.svg[Tiger,100,opts=inline,link=self]', safe: Asciidoctor::SafeMode::SERVER, attributes: { 'imagesdir' => 'fixtures', 'docdir' => testdir }
+ result = para.sub_macros(para.source).gsub(/>\s+</, '><')
+ assert_match(/<svg\s[^>]*width="100"[^>]*>/, result)
+ refute_match(/<a href=/, result)
+ end
+
test 'an image macro with an inline SVG image should be converted to an svg element even when data-uri is set' do
para = block_from_string 'image:circle.svg[Tiger,100,opts=inline]', safe: Asciidoctor::SafeMode::SERVER, attributes: { 'data-uri' => '', 'imagesdir' => 'fixtures', 'docdir' => testdir }
assert_match(/<svg\s[^>]*width="100">/, para.sub_macros(para.source).gsub(/>\s+</, '><'))
@@ -814,6 +821,19 @@ context 'Substitutions' do
para.sub_macros(para.source).gsub(/>\s+</, '><')
end
+ test 'a single-line image macro with text and link to self should be interpreted as a self-referencing image with alt text' do
+ para = block_from_string 'image:tiger.png[Tiger, link=self]', attributes: { 'imagesdir' => 'img' }
+ assert_equal '<span class="image"><a class="image" href="img/tiger.png"><img src="img/tiger.png" alt="Tiger"></a></span>',
+ para.sub_macros(para.source).gsub(/>\s+</, '><')
+ end
+
+ test 'should link to data URI if value of link attribute is self and inline image is embedded' do
+ para = block_from_string 'image:circle.svg[Tiger,100,link=self]', safe: Asciidoctor::SafeMode::SERVER, attributes: { 'data-uri' => '', 'imagesdir' => 'fixtures', 'docdir' => testdir }
+ output = para.sub_macros(para.source).gsub(/>\s+</, '><')
+ assert_xpath '//a[starts-with(@href,"data:image/svg+xml;base64,")]', output, 1
+ assert_xpath '//img[starts-with(@src,"data:image/svg+xml;base64,")]', output, 1
+ end
+
test 'rel=noopener should be added to an image with a link that targets the _blank window' do
para = block_from_string 'image:tiger.png[Tiger,link=http://en.wikipedia.org/wiki/Tiger,window=_blank]'
assert_equal '<span class="image"><a class="image" href="http://en.wikipedia.org/wiki/Tiger" target="_blank" rel="noopener"><img src="tiger.png" alt="Tiger"></a></span>',