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

View file

@ -29,6 +29,8 @@ As buffer options are merged with the defaults, the above headline will be expor
<td>toc</td>
<td>Include table of contents (outline)</td>
</tr>
</tbody>
<tbody>
<tr>
<td>pri</td>
<td>Include priority <code class="verbatim">[#A]</code>, <code class="verbatim">[#B]</code>, <code class="verbatim">[#C]</code> in headline title</td>

View file

@ -151,3 +151,43 @@ table with aligned and sized columns
table with right aligned columns (because numbers)
</figcaption>
</figure>
<figure>
<table>
<thead>
<tr>
<th class="align-right">a</th>
<th class="align-right">b</th>
<th class="align-right">c</th>
</tr>
</thead>
<tbody>
<tr>
<td class="align-right">1</td>
<td class="align-right">2</td>
<td class="align-right">3</td>
</tr>
<tr>
<td class="align-right">.</td>
<td class="align-right">.</td>
<td class="align-right">.</td>
</tr>
</tbody>
<tbody>
<tr>
<td class="align-right">1</td>
<td class="align-right">2</td>
<td class="align-right">3</td>
</tr>
</tbody>
<tbody>
<tr>
<td class="align-right">1</td>
<td class="align-right">2</td>
<td class="align-right">3</td>
</tr>
</tbody>
</table>
<figcaption>
table with multiple separators (~ multiple tbodies)
</figcaption>
</figure>

View file

@ -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 |

View file

@ -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 |