aboutsummaryrefslogtreecommitdiff
path: root/html_backend.go
diff options
context:
space:
mode:
authorShulhan <m.shulhan@gmail.com>2020-12-04 03:42:39 +0700
committerShulhan <m.shulhan@gmail.com>2020-12-04 03:42:39 +0700
commit83ff35e591f0e7c23b6315fb8b6b836e1bcfb803 (patch)
tree499d5592452fc8ddb8b66adaad41d898027811ea /html_backend.go
parent0c1fa764757682dd2ae27ad24ca7f0b6e99c7494 (diff)
downloadasciidoctor-go-83ff35e591f0e7c23b6315fb8b6b836e1bcfb803.tar.xz
all: support setting table width and with autowidth option
Diffstat (limited to 'html_backend.go')
-rw-r--r--html_backend.go38
1 files changed, 26 insertions, 12 deletions
diff --git a/html_backend.go b/html_backend.go
index a9acad4..af8f05c 100644
--- a/html_backend.go
+++ b/html_backend.go
@@ -537,26 +537,40 @@ func hmltWriteSectionDiscrete(doc *Document, node *adocNode, out io.Writer) {
}
func htmlWriteTable(doc *Document, node *adocNode, out io.Writer) {
- var footer *tableRow
+ var (
+ footer *tableRow
+ table = node.table
+ )
- if node.table == nil {
+ if table == nil {
return
}
- fmt.Fprint(out, "\n<table class=\"tableblock frame-all grid-all stretch\">")
+
+ fmt.Fprintf(out, "\n<table class=%q", table.classes.String())
+
+ style := table.htmlStyle()
+ if len(style) > 0 {
+ fmt.Fprintf(out, " style=%q", style)
+ }
+ fmt.Fprint(out, ">")
fmt.Fprint(out, "\n<colgroup>")
- for _, format := range node.table.formats {
- fmt.Fprintf(out, "\n<col style=\"width: %s%%;\">",
- format.width)
+ for _, format := range table.formats {
+ if format.width != nil {
+ fmt.Fprintf(out, "\n<col style=\"width: %s%%;\">",
+ format.width)
+ } else {
+ fmt.Fprint(out, "\n<col>")
+ }
}
fmt.Fprint(out, "\n</colgroup>")
- rows := node.table.rows
- if node.table.hasHeader {
+ rows := table.rows
+ if table.hasHeader {
htmlWriteTableHeader(doc, rows[0], out)
rows = rows[1:]
}
- if node.table.hasFooter && len(rows) > 0 {
+ if table.hasFooter && len(rows) > 0 {
footer = rows[len(rows)-1]
rows = rows[:len(rows)-1]
}
@@ -564,13 +578,13 @@ func htmlWriteTable(doc *Document, node *adocNode, out io.Writer) {
if len(rows) > 0 {
fmt.Fprint(out, "\n<tbody>")
for _, row := range rows {
- htmlWriteTableRow(doc, node.table, row, out)
+ htmlWriteTableRow(doc, table, row, out)
}
fmt.Fprint(out, "\n</tbody>")
}
- if node.table.hasFooter && footer != nil {
- htmlWriteTableFooter(doc, node.table, footer, out)
+ if table.hasFooter && footer != nil {
+ htmlWriteTableFooter(doc, table, footer, out)
}
fmt.Fprint(out, "\n</table>")