Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolves #2521 don't hyphenate autolink when hyphenation is enabled #2513

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Improvements::
* drop support for the unmaintained payment font (`pf`) for use in font-based icons
* refactor formatted text transform to simplify how inner space is collapsed; verify only inner hard breaks are preserved
* allow relative font size for sub and sup to be set independently; support combined setting for backwards compatibility
* don't hyphenate autolink when hyphenation is enabled (#2521) (*@meonkeys*)

Bug Fixes::

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 <<~'END', 'hyphens-word-break.pdf'
:hyphens:
Expand Down
Loading