diff options
| -rw-r--r-- | CHANGELOG.adoc | 1 | ||||
| -rw-r--r-- | lib/asciidoctor/pdf/converter.rb | 15 | ||||
| -rw-r--r-- | spec/pass_spec.rb | 12 | ||||
| -rw-r--r-- | spec/stem_spec.rb | 65 |
4 files changed, 80 insertions, 13 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 069be6a7..18425e58 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -20,6 +20,7 @@ Improvements:: * configure spacing around thematic break using `thematic-break-padding` key instead of margin top and bottom (#2164) * rename `convert_listing_or_literal` to `convert_code` and alias old name +* reify convert handler for STEM blocks (`convert_stem`) Bug Fixes:: diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb index 19572dd8..d2c9f6ae 100644 --- a/lib/asciidoctor/pdf/converter.rb +++ b/lib/asciidoctor/pdf/converter.rb @@ -1917,7 +1917,20 @@ module Asciidoctor node.instance_variable_set :@subs, prev_subs end - alias convert_stem convert_code + def convert_stem node + arrange_block node do |extent| + add_dest_for_block node if node.id + tare_first_page_content_stream { theme_fill_and_stroke_block :code, extent, caption_node: node } + pad_box @theme.code_padding, node do + theme_font :code do + typeset_formatted_text [text: (guard_indentation node.content), color: @font_color], + (calc_line_metrics @base_line_height), + bottom_gutter: @bottom_gutters[-1][node] + end + end + end + theme_margin :block, :bottom, (next_enclosed_block node) + end # Extract callout marks from string, indexed by 0-based line number # Return an Array with the processed string as the first argument diff --git a/spec/pass_spec.rb b/spec/pass_spec.rb index e7ed91d8..02a14a1a 100644 --- a/spec/pass_spec.rb +++ b/spec/pass_spec.rb @@ -30,16 +30,4 @@ describe 'Asciidoctor::PDF::Converter - Pass' do margin_bottom = pass_text[:y] - (para_text[:y] + para_text[:font_size]) (expect margin_bottom).to be > 12 end - - it 'should render stem as code block if stem extension not present' do - pdf = to_pdf <<~'EOS', analyze: true - [stem] - ++++ - sig = enc(H(D), s) - ++++ - EOS - - equation_text = (pdf.find_text 'sig = enc(H(D), s)')[0] - (expect equation_text[:font_name]).to eql 'mplus1mn-regular' - end end diff --git a/spec/stem_spec.rb b/spec/stem_spec.rb new file mode 100644 index 00000000..ae46141e --- /dev/null +++ b/spec/stem_spec.rb @@ -0,0 +1,65 @@ +# frozen_string_literal: true + +require_relative 'spec_helper' + +describe 'Asciidoctor::PDF::Converter - STEM' do + it 'should render stem as code block if stem extension not present' do + pdf = to_pdf <<~'EOS', analyze: true + [stem] + ++++ + sig = enc(H(D), s) + ++++ + + after + EOS + + equation_text = (pdf.find_text 'sig = enc(H(D), s)')[0] + (expect equation_text[:font_name]).to eql 'mplus1mn-regular' + after_text = pdf.find_unique_text 'after' + (expect equation_text[:y] - after_text[:y]).to be > 36 + end + + it 'should preserve indentation in stem block' do + pdf = to_pdf <<~'EOS', pdf_theme: { page_margin: 36, code_padding: 10 }, analyze: true + [stem] + ++++ + M = \left[ + \begin{array}{ c c } + 1 & 2 \\ + 3 & 4 + \end{array} \right] + ++++ + EOS + + pdf.text.each {|text| (expect text[:font_name]).to eql 'mplus1mn-regular' } + lhs_text = pdf.find_unique_text %r/^M/ + (expect lhs_text[:x]).to eql 46.0 + begin_text = pdf.find_unique_text %r/begin/ + (expect begin_text[:x]).to eql 46.0 + (expect begin_text[:string]).to start_with %(\u00a0 ) + end + + it 'should show caption and anchor above block if specified' do + input = <<~'EOS' + // listing-caption is not used in this case + :listing-caption: Listing + + .A basic matrix + [stem#matrix] + ++++ + M = \left[ + \begin{array}{ c c } + 1 & 2 \\ + 3 & 4 + \end{array} \right] + ++++ + EOS + + pdf = to_pdf input, analyze: true + caption_text = pdf.find_unique_text 'A basic matrix' + (expect caption_text[:font_name]).to eql 'NotoSerif-Italic' + lhs_text = pdf.find_unique_text %r/^M/ + (expect caption_text[:y]).to be > lhs_text[:y] + (expect get_names (to_pdf input)).to have_key 'matrix' + end +end |
