From 0f2ebcae5d736324dc0464fa73eaae8b63af919c Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Fri, 27 Dec 2019 17:01:15 -0700 Subject: [PATCH] resolves #444 allow theme to specify border for admonition block --- CHANGELOG.adoc | 1 + lib/asciidoctor/pdf/converter.rb | 9 +++++++++ spec/admonition_spec.rb | 33 ++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 270d9a897..695269385 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -19,6 +19,7 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[ * don't add mailto: prefix to revealed mailto URI when hide-uri-scheme is set (#920) * allow theme to set base text decoration width (#1414) * allow theme to set font-kerning per category (#1431) +* allow theme to specify border for admonition block (#444) * allow text alignment roles to be used to control alignment of discrete heading * use font color from pygments style for unhighlighted text (#1441) * render stem block as raw literal block diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb index b0dd6a267..1c4b9adbb 100644 --- a/lib/asciidoctor/pdf/converter.rb +++ b/lib/asciidoctor/pdf/converter.rb @@ -761,6 +761,15 @@ def convert_admonition node shift_bottom = (shift_base * 2) / 3.0 keep_together do |box_height = nil| push_scratch doc if scratch? + if box_height + if (b_width = @theme.admonition_border_width || 0) > 0 && (b_color = @theme.admonition_border_color) + float do + bounding_box [0, cursor], width: bounds.width, height: box_height do + fill_and_stroke_bounds nil, b_color, line_width: b_width, radius: @theme.admonition_border_radius + end + end + end + end pad_box [0, cpad[1], 0, lpad[3]] do if box_height if (rule_color = @theme.admonition_column_rule_color) && diff --git a/spec/admonition_spec.rb b/spec/admonition_spec.rb index 9cbd97caf..8ccb350cd 100644 --- a/spec/admonition_spec.rb +++ b/spec/admonition_spec.rb @@ -221,4 +221,37 @@ (expect question_text).not_to be_nil end end + + context 'Lines' do + it 'should allow theme to customize color and width of column rule' do + pdf_theme = { + admonition_column_rule_color: '222222', + admonition_column_rule_width: 2, + } + pdf = to_pdf <<~'EOS', pdf_theme: pdf_theme, analyze: :line + TIP: You can use the theme to customize the color and width of the column rule. + EOS + + lines = pdf.lines + (expect lines).to have_size 1 + column_rule = lines[0] + (expect column_rule[:from][:x]).to eql column_rule[:to][:x] + (expect column_rule[:color]).to eql '222222' + (expect column_rule[:width]).to eql 2 + end + + it 'should allow theme to add border', visual: true do + pdf_theme = { + admonition_border_width: 0.5, + admonition_border_radius: 5, + admonition_border_color: 'e0e0e0', + admonition_column_rule_color: 'e0e0e0', + } + to_file = to_pdf_file <<~'EOS', 'admonition-border.pdf', pdf_theme: pdf_theme + TIP: You can use the theme to add a border. + EOS + + (expect to_file).to visually_match 'admonition-border.pdf' + end + end end