From e076412b295cbaa594f882bd7a27795ad7c7e4a9 Mon Sep 17 00:00:00 2001 From: Niklas Fasching Date: Fri, 26 Jun 2020 20:07:03 +0200 Subject: [PATCH] html: Implement fat table rows (use tbodies to represent separators) html does not support table separator rows as Org mode does. Emacs org export simulates rows as defined by separators by wrapping all the rows between 2 separators into a separate tbody. The html spec is fine with that [0] so we follow. [0] https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tbody --- org/html_writer.go | 32 +++++++++++++++++---------- org/testdata/options.html | 2 ++ org/testdata/tables.html | 40 ++++++++++++++++++++++++++++++++++ org/testdata/tables.org | 10 +++++++++ org/testdata/tables.pretty_org | 10 +++++++++ 5 files changed, 82 insertions(+), 12 deletions(-) diff --git a/org/html_writer.go b/org/html_writer.go index bfc002a..7c5c6d3 100644 --- a/org/html_writer.go +++ b/org/html_writer.go @@ -459,23 +459,31 @@ func (w *HTMLWriter) WriteNodeWithName(n NodeWithName) { func (w *HTMLWriter) WriteTable(t Table) { w.WriteString("\n") - beforeFirstContentRow := true + inHead := len(t.SeparatorIndices) > 0 && + t.SeparatorIndices[0] != len(t.Rows)-1 && + (t.SeparatorIndices[0] != 0 || len(t.SeparatorIndices) > 1 && t.SeparatorIndices[len(t.SeparatorIndices)-1] != len(t.Rows)-1) + if inHead { + w.WriteString("\n") + } else { + w.WriteString("\n") + } for i, row := range t.Rows { - if row.IsSpecial || len(row.Columns) == 0 { - continue - } - if beforeFirstContentRow { - beforeFirstContentRow = false - if i+1 < len(t.Rows) && len(t.Rows[i+1].Columns) == 0 { - w.WriteString("\n") - w.writeTableColumns(row.Columns, "th") + if len(row.Columns) == 0 && i != 0 && i != len(t.Rows)-1 { + if inHead { w.WriteString("\n\n") - continue + inHead = false } else { - w.WriteString("\n") + w.WriteString("\n\n") } } - w.writeTableColumns(row.Columns, "td") + if row.IsSpecial { + continue + } + if inHead { + w.writeTableColumns(row.Columns, "th") + } else { + w.writeTableColumns(row.Columns, "td") + } } w.WriteString("\n
\n") } diff --git a/org/testdata/options.html b/org/testdata/options.html index bdf6c50..f003629 100644 --- a/org/testdata/options.html +++ b/org/testdata/options.html @@ -29,6 +29,8 @@ As buffer options are merged with the defaults, the above headline will be expor toc Include table of contents (outline) + + pri Include priority [#A], [#B], [#C] in headline title diff --git a/org/testdata/tables.html b/org/testdata/tables.html index f31e84d..14729a0 100644 --- a/org/testdata/tables.html +++ b/org/testdata/tables.html @@ -151,3 +151,43 @@ table with aligned and sized columns table with right aligned columns (because numbers) +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
abc
123
...
123
123
+
+table with multiple separators (~ multiple tbodies) +
+
diff --git a/org/testdata/tables.org b/org/testdata/tables.org index 215c540..271c259 100644 --- a/org/testdata/tables.org +++ b/org/testdata/tables.org @@ -36,3 +36,13 @@ | long column a | long column b | long column c | |---------------+---------------+---------------| | 1 | 2 | 3 | + +#+CAPTION: table with multiple separators (~ multiple tbodies) +| a | b | c | +|---+---+---| +| 1 | 2 | 3 | +| . | . | . | +|---+---+---| +| 1 | 2 | 3 | +|---+---+---| +| 1 | 2 | 3 | diff --git a/org/testdata/tables.pretty_org b/org/testdata/tables.pretty_org index 215c540..271c259 100644 --- a/org/testdata/tables.pretty_org +++ b/org/testdata/tables.pretty_org @@ -36,3 +36,13 @@ | long column a | long column b | long column c | |---------------+---------------+---------------| | 1 | 2 | 3 | + +#+CAPTION: table with multiple separators (~ multiple tbodies) +| a | b | c | +|---+---+---| +| 1 | 2 | 3 | +| . | . | . | +|---+---+---| +| 1 | 2 | 3 | +|---+---+---| +| 1 | 2 | 3 |