#2128 tables in fandoc?

mike Fri 5 Apr 2013

Is it possible to generate tables with fandoc?

andy Fri 5 Apr 2013

Nope - the formatting required is sort of a nightmare to keep straight. Pretty sure Markdown just reverts to embedding HTML. I've wanted to do this a few times myself so might be nice to add support for.

brian Sat 6 Apr 2013

I typically just use code block and line things up in plaintext

SlimerDude Fri 21 Nov 2014

Whereas you can't parse fandoc into a table structure / table objects, you can parse individual pre and paragraph objects. Think of it as a second wave of parsing.

Fancordion does this when it generates HTML from fandoc. It scans the first line of pre blocks and if it is table: or syntax:table the block is treated as a simple table.

Examples:

syntax: table

Full Name    First Name  Last Name
-----------  ----------  ---------
John Smith   John        Smith
Fred Bloggs  Fred        Bloggs
Steve Eynon  Steve       Eynon

or even:

syntax: table
+-------------+-------+--------+
|             | First | Last   |
| Full Name   | Name  | Name   |
 -------------+-------+--------+
| John Smith  | John  | Smith  |
| Steve Eynon | Steve | Eynon  |
| Fred Bloggs | Fred  | Bloggs |
+-------------+-------+--------+

This way, as Brain suggests, the tables look natural in fandoc notation but has the advantage of being rendered as real HTML tables. (You'll need a special HtmlDocWriter.)

The table parsing I use is simple but expressive. The first line to start with a - character defines where the column boundaries are. All lines before are table headers, all lines after are table data. Any lines consisting entirely of - or + characters are ignored.

See TableParser.fan for the code that parses the pre block into a Str[][] table structure.

The syntax:XXXX trick is one I use a lot. For example, I use it in Fantom-Factory Articles to decide on the syntax highlighting, e.g. syntax: fantom

Login or Signup to reply.