Skip to content

Commit

Permalink
don't show link URL next to link text when media is not screen and sh…
Browse files Browse the repository at this point in the history
…ow-link-uri is unset
  • Loading branch information
mojavelinux committed Jul 15, 2021
1 parent a6ab44d commit a83e3ed
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Enhancements::
* allow theme to control border style of delimited blocks (example, sidebar, code, admonition, verse, quote) (#1586)
* allow theme to control font color of first line of abstract
* allow theme to control background color and border offset (only for background) for links (#1705)
* don't show link URL next to link text when media is not screen and show-link-uri is unset
* don't render index section if index is empty (i.e., there are no index entries)
* stabilize font paths in built-in themes by prefixing paths with GEM_FONTS_DIR (#1568)
* assign page-layout attribute in running content so it can be used select background per layout (#1570)
Expand All @@ -44,6 +45,7 @@ Enhancements::
* configure AsciiDoc table cell to inherit font properties from table and scale font size of nested blocks (#926)
* scale font size of literal table cell (#1696)
* add support for id attribute on link macro
* add support for link attribute on icon macro (#1915)
* allow theme to configure width of block border on ends separate from sides (#1693)
* add additional glyphs to built-in fonts (heavy checkmark to fallback font; both checkmarks to monospaced font; numero sign to prose and fallback fonts) (#1625)
* allow theme to specify text decoration style, color, and width for captions (globally)
Expand All @@ -65,7 +67,6 @@ Enhancements::
* allow theme to control top margin of callout lists that immediately follow a code (i.e., listing, literal, or source) block (#1895)
* introduce layout_general_heading to allow extended converter to access node (#1904)
* use Document#authors to retrieve authors instead of extracting the information from the indexed document attributes
* support link attribute on icon macro (#1915)

Bug Fixes::

Expand Down
4 changes: 2 additions & 2 deletions lib/asciidoctor/pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def log severity, message = nil, &block
def convert_document doc
doc.promote_preface_block
init_pdf doc
# set default value for outline and pagenums if not otherwise set
# set default value for outline, pagenums, and show-link-uri if not otherwise set
doc.attributes['outline'] = '' unless (doc.attribute_locked? 'outline') || ((doc.instance_variable_get :@attributes_modified).include? 'outline')
doc.attributes['pagenums'] = '' unless (doc.attribute_locked? 'pagenums') || ((doc.instance_variable_get :@attributes_modified).include? 'pagenums')
#assign_missing_section_ids doc
Expand Down Expand Up @@ -2463,7 +2463,7 @@ def convert_inline_anchor node
# QUESTION: should we insert breakable chars into URI when building fragment instead?
%(#{anchor}<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
%(#{anchor}<a href="#{target}"#{attrs.join}>#{text}</a> [<font size="0.85em">#{breakable_uri bare_target}</font>&#93;)
Expand Down
32 changes: 32 additions & 0 deletions spec/link_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,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 a83e3ed

Please sign in to comment.