diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2022-05-21 13:19:09 -0600 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2022-05-21 13:29:55 -0600 |
| commit | f2e64831f2698d101ccce77ba5d048525fb1ecac (patch) | |
| tree | 68312cb20ed8282e1703cfc778d89a2142de760e | |
| parent | 75ca02da51c796ee83115692fe53e53787de17ec (diff) | |
follow-up to #2198 hide linenum spacer in source block from wrap by char logic
| -rw-r--r-- | lib/asciidoctor/pdf/formatted_text/source_wrap.rb | 2 | ||||
| -rw-r--r-- | spec/source_spec.rb | 51 |
2 files changed, 52 insertions, 1 deletions
diff --git a/lib/asciidoctor/pdf/formatted_text/source_wrap.rb b/lib/asciidoctor/pdf/formatted_text/source_wrap.rb index 0b190ee8..f1230ee9 100644 --- a/lib/asciidoctor/pdf/formatted_text/source_wrap.rb +++ b/lib/asciidoctor/pdf/formatted_text/source_wrap.rb @@ -17,7 +17,7 @@ module Asciidoctor until stop if (first_fragment = unconsumed[0])[:linenum] linenum_text = first_fragment[:text] - linenum_spacer ||= { text: (NoBreakSpace.encode linenum_text.encoding) + (' ' * (linenum_text.length - 1)) } + linenum_spacer ||= { text: (NoBreakSpace.encode linenum_text.encoding) + (' ' * (linenum_text.length - 1)), linenum: :spacer } highlight_line = (second_fragment = unconsumed[1])[:highlight] ? second_fragment.dup : nil else # wrapped line first_fragment[:text] = first_fragment[:text].lstrip diff --git a/spec/source_spec.rb b/spec/source_spec.rb index 51d0e80f..2960de03 100644 --- a/spec/source_spec.rb +++ b/spec/source_spec.rb @@ -930,6 +930,57 @@ describe 'Asciidoctor::PDF::Converter - Source' do lines = (to_pdf input, pdf_theme: { code_border_radius: 0, code_border_width: [1, 0] }, analyze: :line).lines (expect (lines[0][:from][:y] - lines[1][:from][:y]).abs).to (be_within 2).of 50 end + + it 'should break and wrap numbered line if indented text does not fit on a single line' do + input = <<~EOS + :source-highlighter: rouge + + [%linenums,text] + ---- + before + #{' ' * 2}y#{'o' * 100} + after + ---- + EOS + + pdf = to_pdf input, analyze: true + (expect pdf.pages).to have_size 1 + text_lines = pdf.lines pdf.text + # FIXME: we lose the indentation on the second line, but that's true of plain listing blocks too + expected_lines = <<~EOS.chomp.split ?\n + 1 before + 2 + \u00a0 yooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo + \u00a0 ooooooooooooooooo + 3 after + EOS + (expect text_lines).to eql expected_lines + end + + it 'should break and wrap numbered line if text wraps but still does not fit on a single line' do + input = <<~EOS + :source-highlighter: rouge + + [%linenums,text] + ---- + one + two and then s#{'o' * 100}me + three + ---- + EOS + + pdf = to_pdf input, analyze: true + (expect pdf.pages).to have_size 1 + text_lines = pdf.lines pdf.text + expected_lines = <<~EOS.chomp.split ?\n + 1 one + 2 two and then + \u00a0 sooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo + \u00a0 ooooooooooooooooome + 3 three + EOS + (expect text_lines).to eql expected_lines + end end context 'CodeRay' do |
