From a83e3edb97864d586e2b42fb83e7e2695a3ebad7 Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Wed, 14 Jul 2021 23:58:25 -0600 Subject: [PATCH] don't show link URL next to link text when media is not screen and show-link-uri is unset --- CHANGELOG.adoc | 3 ++- lib/asciidoctor/pdf/converter.rb | 4 ++-- spec/link_spec.rb | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 563b15c64..cad306d61 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -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) @@ -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) @@ -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:: diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb index 731807d9b..2dff69abb 100644 --- a/lib/asciidoctor/pdf/converter.rb +++ b/lib/asciidoctor/pdf/converter.rb @@ -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 @@ -2463,7 +2463,7 @@ def convert_inline_anchor node # QUESTION: should we insert breakable chars into URI when building fragment instead? %(#{anchor}#{breakable_uri text}) # 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}#{text} [#{breakable_uri bare_target}]) diff --git a/spec/link_spec.rb b/spec/link_spec.rb index 17372f357..5a81ccdf5 100644 --- a/spec/link_spec.rb +++ b/spec/link_spec.rb @@ -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]',