Skip to content

Commit

Permalink
Add full support for table captions
Browse files Browse the repository at this point in the history
Progresses #32
  • Loading branch information
Witiko committed Apr 18, 2019
1 parent 55fec88 commit 8d0fe1f
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 13 deletions.
97 changes: 89 additions & 8 deletions markdown.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -4295,7 +4295,7 @@ defaultOptions.inlineFootnotes = false
%</lua,lua-cli>
%<*manual-options>

#### Option `pipeTables`
#### Option `pipeTables` {#pipe-tables}

`pipeTables` (default value: `false`)

Expand All @@ -4314,8 +4314,6 @@ defaultOptions.inlineFootnotes = false
| 12 | 12 | 12 | 12 |
| 123 | 123 | 123 | 123 |
| 1 | 1 | 1 | 1 |

: Demonstration of pipe table syntax.
``````

: false
Expand Down Expand Up @@ -5042,6 +5040,53 @@ defaultOptions.startNumber = true
%</lua,lua-cli>
%<*manual-options>

#### Option `tableCaptions`

`tableCaptions` (default value: `false`)

% \fi
% \begin{markdown}
%
% \Optitem[false]{tableCaptions}{\opt{true}, \opt{false}}
%
: true

: Enable the Pandoc `table_captions` syntax extension for
% pipe tables (see the \Opt{pipeTables} option).
\iffalse
[pipe tables](#pipe-tables).
% \fi

``` md
| Right | Left | Default | Center |
|------:|:-----|---------|:------:|
| 12 | 12 | 12 | 12 |
| 123 | 123 | 123 | 123 |
| 1 | 1 | 1 | 1 |

: Demonstration of pipe table syntax.
``````

: false

: Enable the Pandoc `table_captions` syntax extension.

% \end{markdown}
% \iffalse


%</manual-options>
%<*lua,lua-cli>
% \fi
% \begin{macrocode}
defaultOptions.tableCaptions = false
% \end{macrocode}
% \par
% \iffalse
%</lua,lua-cli>
%<*manual-options>


#### Option `tightLists`

`tightLists` (default value: `true`)
Expand Down Expand Up @@ -5816,6 +5861,7 @@ bug](https://github.com/witiko/markdown/issues).
\let\markdownOptionSlice\undefined
\let\markdownOptionSmartEllipses\undefined
\let\markdownOptionStartNumber\undefined
\let\markdownOptionTableCaptions\undefined
\let\markdownOptionTightLists\undefined
% \end{macrocode}
% \par
Expand Down Expand Up @@ -10019,6 +10065,8 @@ pdflatex --shell-escape document.tex
\def\markdownOptionSlice{#1}}%
\define@key{markdownOptions}{startNumber}[true]{%
\def\markdownOptionStartNumber{#1}}%
\define@key{markdownOptions}{tableCaptions}[true]{%
\def\markdownOptionTableCaptions{#1}}%
\define@key{markdownOptions}{tightLists}[true]{%
\def\markdownOptionTightLists{#1}}%
\define@key{markdownOptions}{underscores}[true]{%
Expand Down Expand Up @@ -12460,7 +12508,8 @@ parsers.define_reference_parser = parsers.leader * parsers.tag * parsers.colon
%
% \end{markdown}
% \begin{macrocode}
parsers.Inline = V("Inline")
parsers.Inline = V("Inline")
parsers.IndentedInline = V("IndentedInline")

-- parse many p between starter and ender
parsers.between = function(p, starter, ender)
Expand Down Expand Up @@ -12828,10 +12877,15 @@ larsers.table_row = pipe_table_row(true
, (C((parsers.linechar - parsers.pipe)^0)
/ parse_inlines)
* parsers.optionalspace)
larsers.table_caption = #parsers.table_caption_beginning
* parsers.table_caption_beginning
* C(parsers.linechar^0) / parse_inlines
* parsers.newline

if options.tableCaptions then
larsers.table_caption = #parsers.table_caption_beginning
* parsers.table_caption_beginning
* Ct(parsers.IndentedInline^1)
* parsers.newline
else
larsers.table_caption = parsers.fail
end

larsers.PipeTable = Ct(larsers.table_row * parsers.newline
* parsers.table_hline
Expand Down Expand Up @@ -12954,6 +13008,9 @@ larsers.PipeTable = Ct(larsers.table_row * parsers.newline
+ larsers.fencestart
) * parsers.spacechar^0 / writer.space

larsers.OptionalIndent
= parsers.spacechar^1 / writer.space

larsers.Space = parsers.spacechar^2 * larsers.Endline / writer.linebreak
+ parsers.spacechar^1 * larsers.Endline^-1 * parsers.eof / ""
+ parsers.spacechar^1 * larsers.Endline^-1
Expand Down Expand Up @@ -13363,8 +13420,29 @@ larsers.PipeTable = Ct(larsers.table_row * parsers.newline
+ V("Smart")
+ V("Symbol"),

IndentedInline = V("Str")
+ V("OptionalIndent")
+ V("Endline")
+ V("UlOrStarLine")
+ V("Strong")
+ V("Emph")
+ V("InlineNote")
+ V("NoteRef")
+ V("Citations")
+ V("Link")
+ V("Image")
+ V("Code")
+ V("AutoLinkUrl")
+ V("AutoLinkEmail")
+ V("InlineHtml")
+ V("HtmlEntity")
+ V("EscapedChar")
+ V("Smart")
+ V("Symbol"),

Str = larsers.Str,
Space = larsers.Space,
OptionalIndent = larsers.OptionalIndent,
Endline = larsers.Endline,
UlOrStarLine = larsers.UlOrStarLine,
Strong = larsers.Strong,
Expand Down Expand Up @@ -13753,6 +13831,9 @@ end
\ifx\markdownOptionStartNumber\undefined\else
startNumber = \markdownOptionStartNumber,
\fi
\ifx\markdownOptionTableCaptions\undefined\else
tableCaptions = \markdownOptionTableCaptions,
\fi
\ifx\markdownOptionTightLists\undefined\else
tightLists = \markdownOptionTightLists,
\fi
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
\def\markdownOptionPipeTables{true}
<<<
This test ensures that the Lua `pipeTables` option correctly propagates through
the plain TeX interface.
This test ensures that the Lua `tableCaptions` option is disabled by
default.

| Right | *Left* | Default | Center |
|------:|:-------|-------------|:------:|
| 12 | 12 | 12 | 12 |
| 123 | 123 | **123** | 123 |
| 1 | 1 | 1 | 1 |

: Demonstration of *pipe table* syntax.
: Demonstration of *pipe table* syntax with the caption spreading over
multiple lines.

A caption may not span multiple paragraphs.
>>>
codeSpan: pipeTables
codeSpan: tableCaptions
interblockSeparator
BEGIN table (4 rows, 4 columns)
- caption: Demonstration of (emphasis: pipe table) syntax.
- caption:
- row 1, column 1: Right
- row 1, column 2: (emphasis: Left)
- row 1, column 3: Default
Expand All @@ -32,3 +35,6 @@ BEGIN table (4 rows, 4 columns)
- row 4, column 3: 1
- row 4, column 4: 1
END table
interblockSeparator
emphasis: pipe table
interblockSeparator
39 changes: 39 additions & 0 deletions tests/testfiles/lunamark-markdown/table-captions.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
\def\markdownOptionPipeTables{true}
\def\markdownOptionTableCaptions{true}
<<<
This test ensures that the Lua `tableCaptions` option correctly propagates
through the plain TeX interface.

| Right | *Left* | Default | Center |
|------:|:-------|-------------|:------:|
| 12 | 12 | 12 | 12 |
| 123 | 123 | **123** | 123 |
| 1 | 1 | 1 | 1 |

: Demonstration of *pipe table* syntax with the caption spreading over
multiple lines.

A caption may not span multiple paragraphs.
>>>
codeSpan: tableCaptions
interblockSeparator
BEGIN table (4 rows, 4 columns)
- caption: Demonstration of (emphasis: pipe table) syntax with the caption spreading over multiple lines.
- row 1, column 1: Right
- row 1, column 2: (emphasis: Left)
- row 1, column 3: Default
- row 1, column 4: Center
- row 2, column 1: 12
- row 2, column 2: 12
- row 2, column 3: 12
- row 2, column 4: 12
- row 3, column 1: 123
- row 3, column 2: 123
- row 3, column 3: (strongEmphasis: 123)
- row 3, column 4: 123
- row 4, column 1: 1
- row 4, column 2: 1
- row 4, column 3: 1
- row 4, column 4: 1
END table
interblockSeparator

0 comments on commit 8d0fe1f

Please sign in to comment.