Skip to content

Commit

Permalink
resolves asciidoctor#444 allow theme to specify border for admonition…
Browse files Browse the repository at this point in the history
… block
  • Loading branch information
mojavelinux committed Dec 28, 2019
1 parent cfb540b commit 2ff7190
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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
Expand Down
9 changes: 9 additions & 0 deletions lib/asciidoctor/pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,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) &&
Expand Down
33 changes: 33 additions & 0 deletions spec/admonition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2ff7190

Please sign in to comment.