Skip to content

Commit

Permalink
resolves #444 allow theme to specify border and background color for …
Browse files Browse the repository at this point in the history
…admonition block (PR #1450)

* allow theme to specify border for admonition block
* allow theme to specify background color for admonition block
  • Loading branch information
mojavelinux authored Dec 30, 2019
1 parent cb35096 commit 4b1f9f3
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ 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 theme to specify background color 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
8 changes: 8 additions & 0 deletions lib/asciidoctor/pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,14 @@ 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 && (@theme.admonition_background_color ||
((@theme.admonition_border_width || 0) > 0 && @theme.admonition_border_color))
float do
bounding_box [0, cursor], width: bounds.width, height: box_height do
theme_fill_and_stroke_bounds :admonition
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
46 changes: 46 additions & 0 deletions spec/admonition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,50 @@
(expect question_text).not_to be_nil
end
end

context 'Background & 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

it 'should allow theme to add background color', visual: true do
pdf_theme = {
admonition_background_color: 'eeeeee',
admonition_border_radius: 3,
admonition_column_rule_width: 0,
}
to_file = to_pdf_file <<~'EOS', 'admonition-background-color.pdf', pdf_theme: pdf_theme
TIP: You can use the theme to add a background color.
EOS

(expect to_file).to visually_match 'admonition-background-color.pdf'
end
end
end
Binary file added spec/reference/admonition-background-color.pdf
Binary file not shown.
Binary file added spec/reference/admonition-border.pdf
Binary file not shown.

0 comments on commit 4b1f9f3

Please sign in to comment.