diff --git a/org/org.go b/org/org.go index a477bd5..d715f79 100644 --- a/org/org.go +++ b/org/org.go @@ -211,8 +211,9 @@ func (w *OrgWriter) writeTable(t Table) { } func (w *OrgWriter) writeTableHeader(th TableHeader) { + w.writeNodes(th.SeparatorBefore) w.writeTableColumns(th.Columns) - w.writeNodes(th.Separator) + w.writeNodes(th.SeparatorAfter) } func (w *OrgWriter) writeTableRow(tr TableRow) { diff --git a/org/table.go b/org/table.go index 3a84939..ccd282d 100644 --- a/org/table.go +++ b/org/table.go @@ -13,8 +13,9 @@ type Table struct { type TableSeparator struct{ Content string } type TableHeader struct { - Columns [][]Node - Separator TableSeparator + SeparatorBefore Node + Columns [][]Node + SeparatorAfter Node } type TableRow struct{ Columns [][]Node } @@ -40,13 +41,24 @@ func (d *Document) parseTable(i int, parentStop stopFn) (int, Node) { } consumed := i - start + if len(rows) >= 2 { if row, ok := rows[0].(TableRow); ok { if separator, ok := rows[1].(TableSeparator); ok { - return consumed, Table{TableHeader{row.Columns, separator}, rows[2:]} + return consumed, Table{TableHeader{nil, row.Columns, separator}, rows[2:]} } } } + if len(rows) >= 3 { + if separatorBefore, ok := rows[0].(TableSeparator); ok { + if row, ok := rows[1].(TableRow); ok { + if separatorAfter, ok := rows[2].(TableSeparator); ok { + return consumed, Table{TableHeader{separatorBefore, row.Columns, separatorAfter}, rows[3:]} + } + } + } + } + return consumed, Table{nil, rows} } diff --git a/org/testdata/tables.html b/org/testdata/tables.html new file mode 100644 index 0000000..fe5843b --- /dev/null +++ b/org/testdata/tables.html @@ -0,0 +1,55 @@ +
+ + + + + + + + + +
abc
123
+
+table with separator before and after header +
+
+
+ + + + + + + + + +
abc
123
+
+table with separator after header +
+
+
+ + + + + + + +
123
+
+table without header (but separator before) +
+
+
+ + + + + + +
123
+
+table without header +
+
diff --git a/org/testdata/tables.org b/org/testdata/tables.org new file mode 100644 index 0000000..56c3fbd --- /dev/null +++ b/org/testdata/tables.org @@ -0,0 +1,18 @@ +#+CAPTION: table with separator before and after header +|---+---+---| +| a | b | c | +|---+---+---| +| 1 | 2 | 3 | + +#+CAPTION: table with separator after header +| a | b | c | +|---+---+---| +| 1 | 2 | 3 | + +#+CAPTION: table without header (but separator before) +|---+---+---| +| 1 | 2 | 3 | + +#+CAPTION: table without header +| 1 | 2 | 3 | +