summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2019-11-20 23:54:29 -0700
committerGitHub <noreply@github.com>2019-11-20 23:54:29 -0700
commite18b883665b8addbdc50e24fd00a35cc422d573d (patch)
treebcacdb66fd227256153998fc73603f1f42457d6e
parent63cb888eb95b789b897a62b1b2df8d82426f9675 (diff)
resolves #1396 ignore invalid cellbgcolor value (PR #1398)
-rw-r--r--CHANGELOG.adoc1
-rw-r--r--lib/asciidoctor/pdf/converter.rb8
-rw-r--r--spec/table_spec.rb15
3 files changed, 20 insertions, 4 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index 82d36f22..87ff2069 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -24,6 +24,7 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[
* allow top value of logo and title on title page to be specified in any measurement unit
* don't set a top value for the logo on the title page if not set in theme
* if value of scripts attribute is cjk, break lines between any two CJK characters except punctuation in table cells (#1359) (*gasol*)
+* ignore invalid cellbgcolor value (#1396)
* recommend installing prawn-gmagick gem if image format is unsupported
* set cache_images option on SVG interface if cache-uri attribute is set on document (#223)
* upgrade prawn-svg to fix display of links in plantuml diagrams (#1105)
diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb
index 6e9475c4..1c40dc3e 100644
--- a/lib/asciidoctor/pdf/converter.rb
+++ b/lib/asciidoctor/pdf/converter.rb
@@ -109,6 +109,7 @@ class Converter < ::Prawn::Document
CjkLineBreakRx = /(?=[\u3000\u30a0-\u30ff\u3040-\u309f\p{Han}\uff00-\uffef])/
WhitespaceChars = ' ' + TAB + LF
ValueSeparatorRx = /;|,/
+ HexColorRx = /^#[a-fA-F0-9]{6}$/
SourceHighlighters = ['coderay', 'pygments', 'rouge'].to_set
PygmentsBgColorRx = /^\.highlight +{ *background: *#([^;]+);/
ViewportWidth = ::Module.new
@@ -2091,8 +2092,11 @@ class Converter < ::Prawn::Document
end
end
if node.document.attr? 'cellbgcolor'
- cell_bg_color = node.document.attr 'cellbgcolor'
- cell_data[:background_color] = cell_bg_color == 'transparent' ? body_bg_color : (cell_bg_color.slice 1, cell_bg_color.length)
+ if (cell_bg_color = node.document.attr 'cellbgcolor') == 'transparent'
+ cell_data[:background_color] = body_bg_color
+ elsif (cell_bg_color.start_with? '#') && (HexColorRx.match? cell_bg_color)
+ cell_data[:background_color] = cell_bg_color.slice 1, cell_bg_color.length
+ end
end
row_data << cell_data
end
diff --git a/spec/table_spec.rb b/spec/table_spec.rb
index cf1fc7db..9bf465dd 100644
--- a/spec/table_spec.rb
+++ b/spec/table_spec.rb
@@ -178,8 +178,6 @@ describe 'Asciidoctor::PDF::Converter - Table' do
it 'should allow value of cellbgcolor attribute in table cell to be transparent', visual: true do
to_file = to_pdf_file <<~'EOS', 'table-cellbgcolor.pdf'
- :attribute-undefined: drop
-
[%autowidth,cols=3*]
|===
| default background color
@@ -191,6 +189,19 @@ describe 'Asciidoctor::PDF::Converter - Table' do
(expect to_file).to visually_match 'table-cellbgcolor.pdf'
end
+ it 'should ignore cellbgcolor attribute if not a valid hex color', visual: true do
+ to_file = to_pdf_file <<~'EOS', 'table-cellbgcolor-invalid.pdf'
+ [%autowidth,cols=3*]
+ |===
+ | {set:cellbgcolor:#f00}default background color
+ | {set:cellbgcolor:#ff0000}red background color
+ | {set:cellbgcolor:bogus}default background color again
+ |===
+ EOS
+
+ (expect to_file).to visually_match 'table-cellbgcolor.pdf'
+ end
+
it 'should use value of cellbgcolor attribute in table cell to override background color set by theme', visual: true do
to_file = to_pdf_file <<~'EOS','table-cellbgcolor-override.pdf', pdf_theme: { table_body_background_color: 'CCCCCC' }
:attribute-undefined: drop