-
Hi, I am turning an OpenAPI spec into markdown using https://github.com/Mermade/widdershins and I can also edit the template to output a nice markdown. One problem is that it outputs lists in some tables and this is not supported in Markdown. My final desired result is Asciidoc, which supports lists in tables. So I came up with an idea of printing tables in html and turn the markdown document (with html tables that contain markdown lists) into Asciidoc using pandoc. However, I can't achieve the desired result. Example input: <table>
<tr><th>Col1</th><th>Col2</th><th>Col3</th><th>Col4</th><th>Col5</th></tr>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
<td>Cell 4</td>
<td>Markdown text
with lists:
* List item 1
* List inside a list
* List inside a list 2
* List inside a list 3
* List item 2
* List item 3
* List item 4 [example link](https://example.com)
Another list:
* Other `list` 1
* **Other** list 2
</td>
</tr>
</table> Using the lua filter from https://tex.stackexchange.com/a/631272: function RawBlock (raw)
return raw.format:match 'html'
and pandoc.read(raw.text, 'html').blocks
or raw
end With the command:
results in the following: [cols=",,,,",options="header",]
|===
|Col1 |Col2 |Col3 |Col4 |Col5
|Cell 1 |Cell 2 |Cell 3 |Cell 4 |Markdown text with lists: * List item 1 * List inside a list * List inside a list 2 * List inside a list 3 * List item 2 * List item 3 * List item 4 [example link](https://example.com) Another list: * Other `list` 1 * **Other** list 2
|=== If I instead use the following lua filter from https://tex.stackexchange.com/a/706748: function RawBlock (raw)
if raw.format:match 'html' then
blocks = pandoc.read(raw.text, 'html').blocks
for i = 1, #blocks do
blocks[i] = pandoc.walk_block(blocks[i],
{
SoftBreak = function(el)
return pandoc.Str("\n")
end,
Plain = function(el)
return pandoc.read(pandoc.utils.stringify(el), 'markdown').blocks
end
}
)
end
return blocks
end
return raw
end with the same command, I end up with: [cols=",,,,",options="header",]
|===
|Col1 |Col2 |Col3 |Col4 |Col5
|Cell 1 |Cell 2 |Cell 3 |Cell 4 |Markdown text with lists: * List item 1 * List inside a list * List inside a list 2 * List inside a list 3 * List item 2 * List item 3 * List item 4 https://example.com[example link] Another list: * Other `+list+` 1 * *Other* list 2
|=== Which is more correct (links are rendered correctly) but the list structure is still lost. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Pandoc's markdown supports grid tables, which do allow lists in them. If you want to convert something like
with markdown content inside HTML tags, you'll need a blank line before and after the markdown content if you're using But what you're doing isn't going to work, anyway -- once pandoc preserves the list structure, it will not emit a pipe table. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the answer and explanation @jgm. For future readers, I instead achieved the result with a few regexes: perl -p -i -e 's/ \* /\n* /g;' test.adoc
perl -p -i -0 -e 's/(\n[^\*\n]+?)\n\* /$1\n\n* /g;' test.adoc |
Beta Was this translation helpful? Give feedback.
Thanks for the answer and explanation @jgm. For future readers, I instead achieved the result with a few regexes: