Skip to content

Commit

Permalink
fix(table): don't crash with subtable-cell in header rows
Browse files Browse the repository at this point in the history
  • Loading branch information
as-op committed Jun 26, 2024
1 parent 0634d84 commit dd18b5c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/md_to_pdf/ext/prawn-table/table/cell/cell/subtable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,12 @@ def width=(new_width)
@subtable.recalculate_positions
@width
end

def font_style=(style)
@subtable.cells.font_style = style
end

def size=(font_size)
@subtable.cells.size = font_size
end
end)
21 changes: 21 additions & 0 deletions spec/fixtures/table/subtable_in_header_row.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<table>
<thead>
<tr>
<th><br></th>
<th>Header 1<img src="demo.jpg"></th>
<th>Header 2</th>
</tr>
</thead>
<tbody>
<tr>
<th>Entry 1</th>
<td></td>
<td></td>
</tr>
<tr>
<th>Entry 2</th>
<td></td>
<td></td>
</tr>
</tbody>
</table>
9 changes: 9 additions & 0 deletions spec/markdown_to_pdf/table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,13 @@
{ x: 396.0, y: 730.884, text: "2. waaa" },
{ x: 396.0, y: 717.012, text: "3. wiiiii" }])
end

it 'creates a html table with subtable in a header row' do
generator.parse_file('table/subtable_in_header_row.md')
expect_pdf([
{ x: 221.0, y: 739.756, text: "Header 1" },
{ x: 396.0, y: 744.756, text: "Header 2" },
{ x: 36.0, y: 578.549, text: "Entry 1" },
{ x: 36.0, y: 564.677, text: "Entry 2" }])
end
end

0 comments on commit dd18b5c

Please sign in to comment.