aboutsummaryrefslogtreecommitdiff
path: root/html_backend.go
diff options
context:
space:
mode:
authorShulhan <m.shulhan@gmail.com>2020-11-20 02:32:09 +0700
committerShulhan <m.shulhan@gmail.com>2020-11-23 00:33:31 +0700
commitf1c0969da998942ea3ef77d041b276b46ec685a6 (patch)
treea9aa248062e7d2d337aea2eda28750457b3d44f8 /html_backend.go
parent4f24d95fa5cb8c7db3e4d123460f83fa2b489cdf (diff)
downloadasciidoctor-go-f1c0969da998942ea3ef77d041b276b46ec685a6.tar.xz
all: implement parser for table
Currently supported format with "cols" options are, * setting number of columns, * setting the horizontal and vertical alignment * setting the column width
Diffstat (limited to 'html_backend.go')
-rw-r--r--html_backend.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/html_backend.go b/html_backend.go
index c63d30b..156e3d9 100644
--- a/html_backend.go
+++ b/html_backend.go
@@ -13,13 +13,20 @@ import (
const (
classNameArticle = "article"
+ classNameHalignCenter = "halign-center"
+ classNameHalignLeft = "halign-left"
+ classNameHalignRight = "halign-right"
classNameListingBlock = "listingblock"
classNameLiteralBlock = "literalblock"
+ classNameTableBlock = "tableblock"
classNameToc = "toc"
classNameToc2 = "toc2"
classNameTocLeft = "toc-left"
classNameTocRight = "toc-right"
classNameUlist = "ulist"
+ classNameValignBottom = "valign-bottom"
+ classNameValignMiddle = "valign-middle"
+ classNameValignTop = "valign-top"
)
const (
@@ -509,6 +516,57 @@ func hmltWriteSectionDiscrete(doc *Document, node *adocNode, out io.Writer) {
fmt.Fprintf(out, "</%s>", tag)
}
+func htmlWriteTable(node *adocNode, out io.Writer) {
+ if node.table == nil {
+ return
+ }
+ fmt.Fprint(out, "\n<table class=\"tableblock frame-all grid-all stretch\">")
+
+ fmt.Fprint(out, "\n<colgroup>")
+ for _, format := range node.table.formats {
+ fmt.Fprintf(out, "\n<col style=\"width: %s%%;\">",
+ format.width)
+ }
+ fmt.Fprint(out, "\n</colgroup>")
+
+ if len(node.table.header) > 0 {
+ htmlWriteTableHeader(node.table.header, out)
+ }
+
+ fmt.Fprint(out, "\n<tbody>")
+ for _, row := range node.table.rows {
+ htmlWriteTableRow(node.table, row, out)
+ }
+ fmt.Fprint(out, "\n</tbody>")
+
+ fmt.Fprint(out, "\n</table>")
+}
+
+func htmlWriteTableHeader(header tableRow, out io.Writer) {
+ classRow := "tableblock halign-left valign-top"
+
+ fmt.Fprint(out, "\n<thead>\n<tr>")
+ for _, col := range header {
+ fmt.Fprintf(out, "\n<th class=%q>%s</th>", classRow, col)
+ }
+ fmt.Fprint(out, "\n</tr>\n</thead>")
+}
+
+func htmlWriteTableRow(table *adocTable, row tableRow, out io.Writer) {
+ classP := "tableblock"
+
+ fmt.Fprint(out, "\n<tr>")
+ for x, col := range row {
+ if x == table.ncols {
+ break
+ }
+ format := table.formats[x]
+ fmt.Fprintf(out, "\n<td class=%q><p class=%q>%s</p></td>",
+ format.htmlClasses(), classP, col)
+ }
+ fmt.Fprint(out, "\n</tr>")
+}
+
func htmlWriteToC(doc *Document, node *adocNode, out io.Writer, level int) {
var sectClass string