Skip to content

Commit

Permalink
resolves #951 allow link URL to be hidden or shown using show-link-ur…
Browse files Browse the repository at this point in the history
…i attribute
  • Loading branch information
mojavelinux committed Dec 31, 2021
1 parent 0d6786e commit 71a9ddf
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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::
Expand Down
2 changes: 1 addition & 1 deletion lib/asciidoctor/pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2357,7 +2357,7 @@ def convert_inline_anchor node
# 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;)
Expand Down
34 changes: 33 additions & 1 deletion spec/link_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
(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.
Expand All @@ -92,6 +92,38 @@
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]',
Expand Down

0 comments on commit 71a9ddf

Please sign in to comment.