Skip to content

Commit f71e589

Browse files
committed
Table: add attrs support to th & td
1 parent 7bc3237 commit f71e589

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

lib/prosemirror_to_html/nodes/table_cell.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ module Nodes
33
class TableCell < Node
44
@node_type = 'table_cell'
55
@tag_name = 'td'
6+
7+
def tag
8+
[
9+
{
10+
tag: self.class.tag_name,
11+
attrs: @node.attrs
12+
}
13+
]
14+
end
615
end
716
end
817
end

lib/prosemirror_to_html/nodes/table_header.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ class TableHeader < TableCell
44
@node_type = 'table_header'
55
@tag_name = 'th'
66

7-
# TODO: support attrs
7+
def tag
8+
[
9+
{
10+
tag: self.class.tag_name,
11+
attrs: @node.attrs
12+
}
13+
]
14+
end
815
end
916
end
1017
end

spec/nodes/table_spec.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
type: 'table_header',
2828
attrs: {
2929
colspan: 2,
30-
colwidth: [100, 0],
3130
},
3231
content: [
3332
{
@@ -140,7 +139,7 @@
140139
],
141140
}
142141

143-
html = '<table><tbody><tr><th><p>text in header cell</p></th><th colspan="2" data-colwidth="100,0"><p>text in header cell with colspan 2</p></th></tr><tr><td rowspan="2"><p>paragraph 1 in cell with rowspan 2</p><p>paragraph 2 in cell with rowspan 2</p></td><td><p>foo</p></td><td><p>bar</p></td></tr><tr><td><p>foo</p></td><td><p>bar</p></td></tr></tbody></table>'
142+
html = '<table><tbody><tr><th><p>text in header cell</p></th><th colspan="2"><p>text in header cell with colspan 2</p></th></tr><tr><td rowspan="2"><p>paragraph 1 in cell with rowspan 2</p><p>paragraph 2 in cell with rowspan 2</p></td><td><p>foo</p></td><td><p>bar</p></td></tr><tr><td><p>foo</p></td><td><p>bar</p></td></tr></tbody></table>'
144143

145144
renderer = ProsemirrorToHtml::Renderer.new
146145
expect(renderer.render(json)).to eq html

0 commit comments

Comments
 (0)