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
This commit is contained in:
Niklas Fasching 2020-06-26 20:07:03 +02:00
parent 5917d8fb1c
commit e076412b29
5 changed files with 82 additions and 12 deletions

View file

@ -459,23 +459,31 @@ func (w *HTMLWriter) WriteNodeWithName(n NodeWithName) {
func (w *HTMLWriter) WriteTable(t Table) {
w.WriteString("<table>\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("<thead>\n")
} else {
w.WriteString("<tbody>\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("<thead>\n")
w.writeTableColumns(row.Columns, "th")
if len(row.Columns) == 0 && i != 0 && i != len(t.Rows)-1 {
if inHead {
w.WriteString("</thead>\n<tbody>\n")
continue
inHead = false
} else {
w.WriteString("<tbody>\n")
w.WriteString("</tbody>\n<tbody>\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("</tbody>\n</table>\n")
}