Skip to content

Commit

Permalink
backport fix for #2521 do not hyphenate autolink when hyphenation is …
Browse files Browse the repository at this point in the history
…enabled
  • Loading branch information
meonkeys authored and mojavelinux committed May 27, 2024
1 parent b0b3c05 commit 97f4e1a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ For a detailed view of what has changed, refer to the {url-repo}/commits/main[co

== Unreleased

Improvements::

* don't hyphenate autolink when hyphenation is enabled (#2521) (*@meonkeys*)

Compliance::

* lock version of rexml (pulled in by asciidoctor-diagram and prawn-svg) to fix incompatibility
Expand Down
11 changes: 10 additions & 1 deletion lib/asciidoctor/pdf/text_transformer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module TextTransformer
TagFilterRx = /(<[^>]+>)|([^<]+)/
ContiguousCharsRx = /\p{Graph}+/
WordRx = /\p{Word}+/
BareClassRx = / class="bare[" ]/
Hyphen = '-'
SoftHyphen = ?\u00ad
LowerAlphaChars = 'a-z'
Expand All @@ -31,7 +32,15 @@ def capitalize_words string

def hyphenate_words_pcdata string, hyphenator
if XMLMarkupRx.match? string
string.gsub(PCDATAFilterRx) { $2 ? (hyphenate_words $2, hyphenator) : $1 }
skipping = false
string.gsub PCDATAFilterRx do
if $2
skipping ? $2 : (hyphenate_words $2, hyphenator)
else
skipping = skipping ? $1 != '</a>' : ($1.start_with? '<a ') && (BareClassRx.match? $1)
$1
end
end
else
hyphenate_words string, hyphenator
end
Expand Down
12 changes: 12 additions & 0 deletions spec/hyphens_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,18 @@
(expect lines[1]).to eql 'graph'
end

it 'should not hyphenate URL of autolink' do
pdf = to_pdf <<~'END', analyze: true
:hyphens:
https://pellentesqueullamcorperpellentesqueullamcorperconsecteturviverrascelerisque.example.com
END

lines = pdf.lines
(expect lines.size).to be > 1
(expect lines[0]).not_to end_with ?\u00ad
end

it 'should show visible hyphen at locate where word is split across lines', visual: true do
to_file = to_pdf_file <<~'EOS', 'hyphens-word-break.pdf'
:hyphens:
Expand Down

0 comments on commit 97f4e1a

Please sign in to comment.