summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2021-12-30 12:53:06 -0700
committerDan Allen <dan.j.allen@gmail.com>2021-12-31 01:08:18 -0700
commit71a9ddf6582afa71346fe809c4a9b5bde3b82fcd (patch)
tree861a58da2115527a6df1928de0eb8ae0895c7d71
parent0d6786e49bbff245cf98f3b15cc2ee2c90ba26ef (diff)
resolves #951 allow link URL to be hidden or shown using show-link-uri attribute
-rw-r--r--CHANGELOG.adoc7
-rw-r--r--lib/asciidoctor/pdf/converter.rb2
-rw-r--r--spec/link_spec.rb34
3 files changed, 41 insertions, 2 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index 6d62a1a5..2317df93 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -5,6 +5,13 @@
This document provides a high-level view of the changes to the {project-name} by release.
For a detailed view of what has changed, refer to the {uri-repo}/commits/v1.6.x[commit history] on GitHub.
+== Unreleased
+
+Enhancements::
+
+* show URL of link for any media type when show-link-uri is set (#951)
+* do not show URL of link when media type is screen or prepress when show-link-uri is unset (#951)
+
== 1.6.1 (2021-09-04) - @mojavelinux
Enhancements::
diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb
index 0eeab4a2..02c43d01 100644
--- a/lib/asciidoctor/pdf/converter.rb
+++ b/lib/asciidoctor/pdf/converter.rb
@@ -2357,7 +2357,7 @@ module Asciidoctor
# QUESTION should we insert breakable chars into URI when building fragment instead?
%(<a href="#{target}"#{attrs.join}>#{breakable_uri text}</a>)
# NOTE @media may not be initialized if method is called before convert phase
- elsif @media != 'screen' || (doc.attr? 'show-link-uri')
+ elsif (doc.attr? 'show-link-uri') || !(@media == 'screen' || (doc.attribute_locked? 'show-link-uri') || ((doc.instance_variable_get :@attributes_modified).include? 'show-link-uri'))
# QUESTION should we insert breakable chars into URI when building fragment instead?
# TODO: allow style of printed link to be controlled by theme
%(<a href="#{target}"#{attrs.join}>#{text}</a> [<font size="0.85em">#{breakable_uri bare_target}</font>&#93;)
diff --git a/spec/link_spec.rb b/spec/link_spec.rb
index 709db628..999fa184 100644
--- a/spec/link_spec.rb
+++ b/spec/link_spec.rb
@@ -82,7 +82,7 @@ describe 'Asciidoctor::PDF::Converter - Link' do
(expect lines[1]).to eql 'https://goo.gl/search/asciidoctor'
end
- it 'should reveal URL of link when media=print or media=prepress' do
+ it 'should reveal URL of link by default when media=print or media=prepress' do
%w(print prepress).each do |media|
pdf = to_pdf <<~'EOS', attribute_overrides: { 'media' => media }, analyze: true
https://asciidoctor.org[Asciidoctor] is a text processor.
@@ -92,6 +92,38 @@ describe 'Asciidoctor::PDF::Converter - Link' do
end
end
+ it 'should reveal URL of link when show-link-uri is set' do
+ pdf = to_pdf <<~'EOS', analyze: true
+ :show-link-uri:
+
+ https://asciidoctor.org[Asciidoctor] is a text processor.
+ EOS
+
+ (expect pdf.lines).to eql ['Asciidoctor [https://asciidoctor.org] is a text processor.']
+ end
+
+ it 'should not reveal URL of link when show-link-uri is unset in document even media is print or prepress' do
+ %w(print prepress).each do |media|
+ pdf = to_pdf <<~'EOS', attribute_overrides: { 'media' => media }, analyze: true
+ :!show-link-uri:
+
+ https://asciidoctor.org[Asciidoctor] is a text processor.
+ EOS
+
+ (expect pdf.lines).to eql ['Asciidoctor is a text processor.']
+ end
+ end
+
+ it 'should not reveal URL of link when show-link-uri is unset from API even media is print or prepress' do
+ %w(print prepress).each do |media|
+ pdf = to_pdf <<~'EOS', attribute_overrides: { 'media' => media, 'show-link-uri' => nil }, analyze: true
+ https://asciidoctor.org[Asciidoctor] is a text processor.
+ EOS
+
+ (expect pdf.lines).to eql ['Asciidoctor is a text processor.']
+ end
+ end
+
it 'should split revealed URL on breakable characters when media=print, media=prepress, or show-link-uri is set' do
inputs = [
'the URL on this line will get split on the ? char https://github.com/asciidoctor/asciidoctor/issues?|q=milestone%3Av2.0.x[link]',