From 8d0fe1f2fb050be30cbb258908cbfcf806fb2080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Novotn=C3=BD?= Date: Thu, 18 Apr 2019 19:53:31 +0200 Subject: [PATCH] Add full support for table captions Progresses #32 --- markdown.dtx | 97 +++++++++++++++++-- ...ipe-tables.test => no-table-captions.test} | 16 ++- .../lunamark-markdown/table-captions.test | 39 ++++++++ 3 files changed, 139 insertions(+), 13 deletions(-) rename tests/testfiles/lunamark-markdown/{pipe-tables.test => no-table-captions.test} (69%) create mode 100644 tests/testfiles/lunamark-markdown/table-captions.test diff --git a/markdown.dtx b/markdown.dtx index 2321c8ef4..a22820a93 100644 --- a/markdown.dtx +++ b/markdown.dtx @@ -4295,7 +4295,7 @@ defaultOptions.inlineFootnotes = false % %<*manual-options> -#### Option `pipeTables` +#### Option `pipeTables` {#pipe-tables} `pipeTables` (default value: `false`) @@ -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 @@ -5042,6 +5040,53 @@ defaultOptions.startNumber = true % %<*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 + + +% +%<*lua,lua-cli> +% \fi +% \begin{macrocode} +defaultOptions.tableCaptions = false +% \end{macrocode} +% \par +% \iffalse +% +%<*manual-options> + + #### Option `tightLists` `tightLists` (default value: `true`) @@ -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 @@ -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]{% @@ -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) @@ -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 @@ -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 @@ -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, @@ -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 diff --git a/tests/testfiles/lunamark-markdown/pipe-tables.test b/tests/testfiles/lunamark-markdown/no-table-captions.test similarity index 69% rename from tests/testfiles/lunamark-markdown/pipe-tables.test rename to tests/testfiles/lunamark-markdown/no-table-captions.test index 1f2e39965..f4e66afe7 100644 --- a/tests/testfiles/lunamark-markdown/pipe-tables.test +++ b/tests/testfiles/lunamark-markdown/no-table-captions.test @@ -1,7 +1,7 @@ \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 | |------:|:-------|-------------|:------:| @@ -9,12 +9,15 @@ the plain TeX interface. | 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 @@ -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 diff --git a/tests/testfiles/lunamark-markdown/table-captions.test b/tests/testfiles/lunamark-markdown/table-captions.test new file mode 100644 index 000000000..0c809e939 --- /dev/null +++ b/tests/testfiles/lunamark-markdown/table-captions.test @@ -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