summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2018-10-10 23:59:16 -0600
committerGitHub <noreply@github.com>2018-10-10 23:59:16 -0600
commit22ee042aca0ade8a642974a737bb3bf08a549201 (patch)
tree78370ad46b458d77a9caf7aabc1edc77b9936758
parent191b740d78c05c554391dba8a33331266f73f981 (diff)
don't hide URI scheme if target of link macro is a bare URI scheme (PR #2909)
-rw-r--r--CHANGELOG.adoc1
-rw-r--r--lib/asciidoctor/substitutors.rb9
-rw-r--r--test/links_test.rb9
3 files changed, 18 insertions, 1 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index 1b69640c..1268c7be 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -51,6 +51,7 @@ Fixes::
* use fallback value for manname-title to prevent crash in manpage converter
* consolidate inner whitespace in prose in manpage output (#2890)
* only apply subs to node attribute value if enclosed in single quotes (#2905)
+ * don't hide URI scheme if target of link macro is a bare URI scheme
Improvements::
diff --git a/lib/asciidoctor/substitutors.rb b/lib/asciidoctor/substitutors.rb
index 167c6f1c..a0b48efa 100644
--- a/lib/asciidoctor/substitutors.rb
+++ b/lib/asciidoctor/substitutors.rb
@@ -825,6 +825,7 @@ module Substitutors
end
if text.empty?
+ # NOTE it's not possible for the URI scheme to be bare in this case
text = (doc_attrs.key? 'hide-uri-scheme') ? (target.sub UriSniffRx, '') : target
if attrs
attrs['role'] = (attrs.key? 'role') ? %(bare #{attrs['role']}) : 'bare'
@@ -893,7 +894,13 @@ module Substitutors
if mailto
text = m[2]
else
- text = (doc_attrs.key? 'hide-uri-scheme') ? (target.sub UriSniffRx, '') : target
+ if doc_attrs.key? 'hide-uri-scheme'
+ if (text = target.sub UriSniffRx, '').empty?
+ text = target
+ end
+ else
+ text = target
+ end
if attrs
attrs['role'] = (attrs.key? 'role') ? %(bare #{attrs['role']}) : 'bare'
else
diff --git a/test/links_test.rb b/test/links_test.rb
index a78664a9..0c122f2b 100644
--- a/test/links_test.rb
+++ b/test/links_test.rb
@@ -26,6 +26,15 @@ context 'Links' do
assert_xpath "//a[@href='file:///etc/app.conf'][text() = '/etc/app.conf']", convert_string('Edit the configuration file link:file:///etc/app.conf[]', :attributes => {'hide-uri-scheme' => ''})
end
+ test 'should not hide bare URI scheme in implicit text of link macro when hide-uri-scheme is set' do
+ {
+ 'link:https://[]' => 'https://',
+ 'link:ssh://[]' => 'ssh://'
+ }.each do |input, expected|
+ assert_xpath %(/a[text() = "#{expected}"]), (convert_inline_string input, :attributes => { 'hide-uri-scheme' => '' })
+ end
+ end
+
test 'qualified url with label' do
assert_xpath "//a[@href='http://asciidoc.org'][text() = 'AsciiDoc']", convert_string("We're parsing http://asciidoc.org[AsciiDoc] markup")
end