Skip to content

Commit

Permalink
features(types/renderer): Table cols attribute support (bytesparadise…
Browse files Browse the repository at this point in the history
…#698)

This adds support for handling the cols attribute ont tables,
giving the ability specify per column widths and alignments.
It also supports the repeat syntax, and the ability to set
autoexpand (either for the entire table or for an individual row).

The width handling and calculations were moved to instantiation
time for the Table, so that all backends can benefit from the
calculation work done for these.

The style component of the column specification is consumed and
stored, but does not affect deeper parsing or rendering yet.

This takes table support about as far as it can go without
reworking the parser to provide context-sensitive parsing of
the table contents.

While here the limitations document was updated to provide more
detail on limitations, including links to issues for folks
who want to track progress.

Fixes bytesparadise#694
Fixes bytesparadise#686
  • Loading branch information
gdamore committed Jul 5, 2020
1 parent fe6293f commit 5af260e
Show file tree
Hide file tree
Showing 10 changed files with 822 additions and 169 deletions.
70 changes: 37 additions & 33 deletions LIMITATIONS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,12 @@
This document reports the known limitations and differences with Asciidoc/Asciidoctor.
In any case, feel free to https://github.com/bytesparadise/libasciidoc/issues[open an issue]
if you want to discuss an actual limitation of Libasciidoc or if you want to report a new one.
We also accept pull requests.

== Quoted Text

Quoted text rendering can differ in the following cases:

- when the punctuation is unbalanced. Eg:
....
some **bold content*.
....
will be rendered as the raw input:
....
some **bold content*.
....
instead of :
....
<p>some <strong>*bold content</strong></p>
....

- when quoted text uses the same punctuation. Eg:
....
*some *nested bold* content*.
....
Libasciidoc will detect the nested bold quote and renderer accordingly:
....
<strong>some <strong>nested bold</strong> content</strong>.
....
whereas Asciidoc/Asciidoctor will produce :
....
<p><strong>some *nested bold</strong> content*.</p>
....
This list is not necessarily complete, but it should reflect the differences
likely to impact real documents.
The entire list of known issues is tracked in https://github.com/bytesparadise/libasciidoc/issues[GitHub].
We plan to address the majority of these issues.

== Two-line Section Titles

Expand Down Expand Up @@ -61,6 +37,7 @@ will produce no HTML element at all, whereas Asciidoc/Asciidoctor will produce :
Constrained or imbalanced monospace text may not act fully constrained, or may be confused in the presence of
imbalanced quoted strings or apostrophes. Typically such markup is erroneous, but the results from such errors may
differ between implementations.
See https://github.com/bytesparadise/libasciidoc/issues/630[Issue #630].

== Attribute Lists

Expand All @@ -74,26 +51,40 @@ Escaping of quotes within quoted strings used as attribute value does not work.

== Tables

Only simple tables are supported. No per-cell table styling, custom delimiters, or unusually formatted tables.
There is no support for the cols table attribute - the number of columns is determined by the number of cells
in the first line of the table.
Custom table delimiters, and custom formats (TSV, CSV, DSV) are not supported.
See https://github.com/bytesparadise/libasciidoc/issues/696[Issue #696].

No support for nested tables.
Tables will not parse if the content starts with a blank line.
See https://github.com/bytesparadise/libasciidoc/issues/692[Issue #692].

Individual cell styles, including spans and repeats, are not supported.
See https://github.com/bytesparadise/libasciidoc/issues/695[Issue #695].

The style attribute for cell contents (specified in the cols attribute) is ignored (the "d" style for inline content is assumed).
See https://github.com/bytesparadise/libasciidoc/issues/694[Issue #694].

The parser will likely be confused by ragged tables, or tables that do not use one line per row.
See https://github.com/bytesparadise/libasciidoc/issues/637[Issue #637].

No support for nested tables. See https://github.com/bytesparadise/libasciidoc/issues/697[Issue #697].

== Lists

Interactive checklists are not supported.
See https://github.com/bytesparadise/libasciidoc/issues/675[Issue #675].

== Images

Interactive SVG support is missing, as is support for inline SVG.
See https://github.com/bytesparadise/libasciidoc/issues/674[Issue #674].

The global figure-caption attribute is not honored.
Use per-image caption attributes for more control if needed.

== Multimedia

Video and audio elements are not supported.
See https://github.com/bytesparadise/libasciidoc/issues/677[Issue #677].

== File Inclusions

Expand All @@ -104,22 +95,27 @@ the "full" parsing.
== Symbols and Characters

Markup for the mdash and arrow symbols is not recognized.
See https://github.com/bytesparadise/libasciidoc/issues/678[Issue #678].

Symbols for quotes (both single and double) will be inlined as numeric HTML entities, even in cases where this is not strictly necessary.

Symbolic entity names (such as `&loz;` for &loz;) are not recognized -- leaving recognition and rendering dependent on the user-agent.
See https://github.com/bytesparadise/libasciidoc/issues/680[Issue #680].

== User Interface Macros

The experimental macros for user interfaces (`kbd`, `menu`, and `btn`) are not supported.
See https://github.com/bytesparadise/libasciidoc/issues/607[Issue #607].

== Admonitions

Use of unicode symbols or other replacement using the per-type caption attribute is not supported.
See https://github.com/bytesparadise/libasciidoc/issues/679[Issue #679].

== Favicon

The `favicon` document attribute is not recognized.
See https://github.com/bytesparadise/libasciidoc/issues/681[Issue #681].

== Syntax Highlighters

Expand All @@ -128,24 +124,30 @@ Only the `pygments` highlighter is recognized.
== Math

MathML and equations (`[stem]` blocks) are not supported yet.
See https://github.com/bytesparadise/libasciidoc/issues/608[Issue #608].

== Bibliographies

Bibliographies using bibtex are not supported yet.
See https://github.com/bytesparadise/libasciidoc/issues/609[Issue #609].

== Links

When using the `*` and `_` characters at the end of URLs of external links in a quoted text, the attributes markers need to be explicitly set. Eg: `+++a link to *https://foo.com/_[]*+++`.

Using the caret short-hand to indicate link targets should use the blank window is not support.
See https://github.com/bytesparadise/libasciidoc/issues/682[Issue #682].

== Document Types

The inline and book document types are not supported. Article and manpage documents work fine.
See https://github.com/bytesparadise/libasciidoc/issues/628[Issue #628] and
https://github.com/bytesparadise/libasciidoc/issues/629[Issue #629].

== CSS

At present no CSS is provided, but the output generated should be compatible with asciidoctor CSS.
See https://github.com/bytesparadise/libasciidoc/issues/63[Issue #63].

== Output Formats (Back-ends)

Expand All @@ -154,3 +156,5 @@ Only HTML and XHTML backends are supported.
== CLI

Support for -d to set the document type is missing.
See https://github.com/bytesparadise/libasciidoc/issues/616[Issue #616].

146 changes: 145 additions & 1 deletion pkg/parser/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ var _ = Describe("tables", func() {
expected := types.DraftDocument{
Blocks: []interface{}{
types.Table{
Columns: []types.TableColumn{
{Width: "50", VAlign: "top", HAlign: "left"},
{Width: "50", VAlign: "top", HAlign: "left"},
},
Lines: []types.TableLine{
{
Cells: [][]interface{}{
Expand Down Expand Up @@ -63,6 +67,11 @@ var _ = Describe("tables", func() {
expected := types.DraftDocument{
Blocks: []interface{}{
types.Table{
Columns: []types.TableColumn{
{Width: "33.3333", VAlign: "top", HAlign: "left"},
{Width: "33.3333", VAlign: "top", HAlign: "left"},
{Width: "33.3334", VAlign: "top", HAlign: "left"},
},
Lines: []types.TableLine{
{
Cells: [][]interface{}{
Expand Down Expand Up @@ -123,6 +132,11 @@ var _ = Describe("tables", func() {
Attributes: types.Attributes{
types.AttrTitle: "table title",
},
Columns: []types.TableColumn{
{Width: "50", HAlign: "left", VAlign: "top"},
{Width: "50", HAlign: "left", VAlign: "top"},
},

Header: types.TableLine{
Cells: [][]interface{}{
{
Expand Down Expand Up @@ -208,7 +222,11 @@ var _ = Describe("tables", func() {
},
},
},

Columns: []types.TableColumn{
// autowidth clears width
{Width: "", HAlign: "left", VAlign: "top"},
{Width: "", HAlign: "left", VAlign: "top"},
},
Lines: []types.TableLine{
{
Cells: [][]interface{}{
Expand Down Expand Up @@ -249,6 +267,132 @@ var _ = Describe("tables", func() {
expected := types.DraftDocument{
Blocks: []interface{}{
types.Table{
Columns: []types.TableColumn{},
Lines: []types.TableLine{},
},
},
}
Expect(ParseDraftDocument(source)).To(MatchDraftDocument(expected))
})

It("empty table with cols attr", func() {
source := "[cols=\"3,2,5\"]\n|===\n|==="
expected := types.DraftDocument{
Blocks: []interface{}{
types.Table{
Attributes: types.Attributes{
types.AttrCols: "3,2,5",
},
Columns: []types.TableColumn{
{Width: "30", HAlign: "left", VAlign: "top"},
{Width: "20", HAlign: "left", VAlign: "top"},
{Width: "50", HAlign: "left", VAlign: "top"},
},
Lines: []types.TableLine{},
},
},
}
Expect(ParseDraftDocument(source)).To(MatchDraftDocument(expected))
})

It("autowidth overrides column widths", func() {
source := "[%autowidth,cols=\"3,2,5\"]\n|===\n|==="
expected := types.DraftDocument{
Blocks: []interface{}{
types.Table{
Attributes: types.Attributes{
types.AttrOptions: map[string]bool{"autowidth": true},
types.AttrCols: "3,2,5",
},
Columns: []types.TableColumn{
{Width: "", HAlign: "left", VAlign: "top"},
{Width: "", HAlign: "left", VAlign: "top"},
{Width: "", HAlign: "left", VAlign: "top"},
},
Lines: []types.TableLine{},
},
},
}
Expect(ParseDraftDocument(source)).To(MatchDraftDocument(expected))
})

It("column autowidth", func() {
source := "[cols=\"30,~,~\"]\n|===\n|==="
expected := types.DraftDocument{
Blocks: []interface{}{
types.Table{
Attributes: types.Attributes{
types.AttrCols: "30,~,~",
},
Columns: []types.TableColumn{
{Width: "30", HAlign: "left", VAlign: "top"},
{Width: "", HAlign: "left", VAlign: "top"},
{Width: "", HAlign: "left", VAlign: "top"},
},
Lines: []types.TableLine{},
},
},
}
Expect(ParseDraftDocument(source)).To(MatchDraftDocument(expected))
})

It("columns with repeat", func() {
source := "[cols=\"3*10,2*~\"]\n|===\n|==="
expected := types.DraftDocument{
Blocks: []interface{}{
types.Table{
Attributes: types.Attributes{
types.AttrCols: "3*10,2*~",
},
Columns: []types.TableColumn{
{Width: "10", HAlign: "left", VAlign: "top"},
{Width: "10", HAlign: "left", VAlign: "top"},
{Width: "10", HAlign: "left", VAlign: "top"},
{Width: "", HAlign: "left", VAlign: "top"},
{Width: "", HAlign: "left", VAlign: "top"},
},
Lines: []types.TableLine{},
},
},
}
Expect(ParseDraftDocument(source)).To(MatchDraftDocument(expected))
})
It("columns with alignment changes", func() {
source := "[cols=\"2*^.^,<,.>\"]\n|===\n|==="
expected := types.DraftDocument{Blocks: []interface{}{
types.Table{
Attributes: types.Attributes{
types.AttrCols: "2*^.^,<,.>",
},
Columns: []types.TableColumn{
{Width: "25", HAlign: "center", VAlign: "middle"},
{Width: "25", HAlign: "center", VAlign: "middle"},
{Width: "25", HAlign: "left", VAlign: "top"},
{Width: "25", HAlign: "left", VAlign: "bottom"},
},
Lines: []types.TableLine{},
},
},
}
Expect(ParseDraftDocument(source)).To(MatchDraftDocument(expected))
})

// TODO: This checks that we parse the styles -- we don't actually do anything with them further yet.
It("columns with alignment changes and styles", func() {
source := "[cols=\"2*^.^d,<e,.>s\"]\n|===\n|==="
expected := types.DraftDocument{
FrontMatter: types.FrontMatter{Content: nil},
Blocks: []interface{}{
types.Table{
Attributes: types.Attributes{
types.AttrCols: "2*^.^d,<e,.>s",
},
Columns: []types.TableColumn{
{Width: "25", HAlign: "center", VAlign: "middle"}, // "d" is aliased to ""
{Width: "25", HAlign: "center", VAlign: "middle"},
{Width: "25", HAlign: "left", VAlign: "top", Style: "e"},
{Width: "25", HAlign: "left", VAlign: "bottom", Style: "s"},
},
Lines: []types.TableLine{},
},
},
Expand Down
10 changes: 5 additions & 5 deletions pkg/renderer/sgml/html5/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ const (
"{{ if .Title }}<caption class=\"title\">{{ .Caption }}{{ .Title }}</caption>\n{{ end }}" +
"{{ if .Body }}" +
"<colgroup>\n" +
"{{ range $i, $w := .CellWidths }}<col style=\"width: {{ $w }}%;\">\n{{ end}}" +
"{{ range $i, $w := .Columns }}<col" +
"{{ if $w.Width }} style=\"width: {{ $w.Width }}%;\"{{ end }}" +
">\n{{ end}}" +
"</colgroup>\n" +
"{{ .Header }}" +
"{{ .Body }}" +
Expand All @@ -27,9 +29,7 @@ const (

tableCaptionTmpl = "Table {{ .TableNumber }}. "

// TODO: cell styling via attributes
tableHeaderCellTmpl = "<th class=\"tableblock halign-{{ .HAlign }} valign-{{ .VAlign }}\">{{ .Content }}</th>\n"

tableHeaderCellTmpl = "<th class=\"tableblock halign-left valign-top\">{{ .Content }}</th>\n"

tableCellTmpl = "<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">{{ .Content }}</p></td>\n"
tableCellTmpl = "<td class=\"tableblock halign-{{ .HAlign }} valign-{{ .VAlign }}\"><p class=\"tableblock\">{{ .Content }}</p></td>\n"
)
Loading

0 comments on commit 5af260e

Please sign in to comment.