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:
parent
5917d8fb1c
commit
e076412b29
5 changed files with 82 additions and 12 deletions
|
@ -459,23 +459,31 @@ func (w *HTMLWriter) WriteNodeWithName(n NodeWithName) {
|
||||||
|
|
||||||
func (w *HTMLWriter) WriteTable(t Table) {
|
func (w *HTMLWriter) WriteTable(t Table) {
|
||||||
w.WriteString("<table>\n")
|
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 {
|
for i, row := range t.Rows {
|
||||||
if row.IsSpecial || len(row.Columns) == 0 {
|
if len(row.Columns) == 0 && i != 0 && i != len(t.Rows)-1 {
|
||||||
continue
|
if inHead {
|
||||||
}
|
|
||||||
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")
|
|
||||||
w.WriteString("</thead>\n<tbody>\n")
|
w.WriteString("</thead>\n<tbody>\n")
|
||||||
continue
|
inHead = false
|
||||||
} else {
|
} 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")
|
w.WriteString("</tbody>\n</table>\n")
|
||||||
}
|
}
|
||||||
|
|
2
org/testdata/options.html
vendored
2
org/testdata/options.html
vendored
|
@ -29,6 +29,8 @@ As buffer options are merged with the defaults, the above headline will be expor
|
||||||
<td>toc</td>
|
<td>toc</td>
|
||||||
<td>Include table of contents (outline)</td>
|
<td>Include table of contents (outline)</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td>pri</td>
|
<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>
|
<td>Include priority <code class="verbatim">[#A]</code>, <code class="verbatim">[#B]</code>, <code class="verbatim">[#C]</code> in headline title</td>
|
||||||
|
|
40
org/testdata/tables.html
vendored
40
org/testdata/tables.html
vendored
|
@ -151,3 +151,43 @@ table with aligned and sized columns
|
||||||
table with right aligned columns (because numbers)
|
table with right aligned columns (because numbers)
|
||||||
</figcaption>
|
</figcaption>
|
||||||
</figure>
|
</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>
|
||||||
|
|
10
org/testdata/tables.org
vendored
10
org/testdata/tables.org
vendored
|
@ -36,3 +36,13 @@
|
||||||
| long column a | long column b | long column c |
|
| long column a | long column b | long column c |
|
||||||
|---------------+---------------+---------------|
|
|---------------+---------------+---------------|
|
||||||
| 1 | 2 | 3 |
|
| 1 | 2 | 3 |
|
||||||
|
|
||||||
|
#+CAPTION: table with multiple separators (~ multiple tbodies)
|
||||||
|
| a | b | c |
|
||||||
|
|---+---+---|
|
||||||
|
| 1 | 2 | 3 |
|
||||||
|
| . | . | . |
|
||||||
|
|---+---+---|
|
||||||
|
| 1 | 2 | 3 |
|
||||||
|
|---+---+---|
|
||||||
|
| 1 | 2 | 3 |
|
||||||
|
|
10
org/testdata/tables.pretty_org
vendored
10
org/testdata/tables.pretty_org
vendored
|
@ -36,3 +36,13 @@
|
||||||
| long column a | long column b | long column c |
|
| long column a | long column b | long column c |
|
||||||
|---------------+---------------+---------------|
|
|---------------+---------------+---------------|
|
||||||
| 1 | 2 | 3 |
|
| 1 | 2 | 3 |
|
||||||
|
|
||||||
|
#+CAPTION: table with multiple separators (~ multiple tbodies)
|
||||||
|
| a | b | c |
|
||||||
|
|---+---+---|
|
||||||
|
| 1 | 2 | 3 |
|
||||||
|
| . | . | . |
|
||||||
|
|---+---+---|
|
||||||
|
| 1 | 2 | 3 |
|
||||||
|
|---+---+---|
|
||||||
|
| 1 | 2 | 3 |
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue