Skip to content

Commit ee7bf29

Browse files
authored
Only allow supported options of prawn-table
1 parent 76d9097 commit ee7bf29

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/prawn/markup/processor/tables.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ def inside_container?
8686
def add_cell_text_node(cell, options = {})
8787
return unless buffered_text?
8888

89+
# only allow on supported options of prawn-table; See https://github.com/prawnpdf/prawn-table/blob/master/manual/table/cell_text.rb
90+
options = options.slice(*%i[font font_style inline_format kerning leading min_font_size size
91+
overflow rotate rotate_around single_line text_color valign])
92+
8993
cell.nodes << options.merge(content: dump_text.strip)
9094
end
9195

spec/prawn/markup/processor/tables_spec.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
processor.parse('<table><tr><td>boot<p>hello</p><p>world</p>and universe</td>' \
6666
'<td><p>other</p><p><br/></p><p>last</p></td></tr></table>')
6767
expect(text.strings).to eq(['boot', 'hello', 'world', 'and universe', 'other', 'last'])
68-
first_sub_col_left = first_col_left + table_padding
6968
expect(left_positions)
7069
.to eq([first_col_left, first_col_left, first_col_left, first_col_left, 342, 342])
7170
expect(top_positions)
@@ -77,11 +76,26 @@
7776
first_row_top - 4 * line].map(&:round))
7877
end
7978

79+
describe 'nested headings' do
80+
let(:options) do
81+
{
82+
heading1: { size: 36, style: :bold },
83+
heading2: { size: 24, style: :bold_italic }
84+
}
85+
end
86+
87+
it 'creates headings inside tables' do
88+
processor.parse('<table><tr><td><h1>hello</h1><h2>world</h2></td></tr></table>')
89+
expect(text.strings).to eq(['hello', 'world'])
90+
expect(left_positions).to eq([first_col_left, first_col_left])
91+
expect(top_positions).to eq([first_row_top - 17, first_row_top - 50].map(&:round))
92+
end
93+
end
94+
8095
it 'creates divs inside tables' do
8196
processor.parse('<table><tr><td>boot<div>hello<div>world</div><div>and universe</div></div>all the rest</td>' \
8297
'<td><div>other</div></td></tr></table>')
8398
expect(text.strings).to eq(['boot', 'hello', 'world', 'and universe', 'all the rest', 'other'])
84-
first_sub_col_left = first_col_left + table_padding
8599
expect(left_positions)
86100
.to eq([first_col_left, first_col_left, first_col_left, first_col_left, first_col_left, 368])
87101
expect(top_positions)

0 commit comments

Comments
 (0)