Docx to Markdown: write tables as HTML #10288
Replies: 3 comments 5 replies
-
Maybe a lua filter like this could work (I did not test it): return {
{
Table: function(t)
if FORMAT == 'markdown' then
local doc = pandoc.Pandoc( { t } )
local html = pandoc.write(doc, 'html')
return pandoc.RawBlock('markdown', html)
end
end,
}
} |
Beta Was this translation helpful? Give feedback.
-
The filter shouldn't be necessary. Tables in Markdown are extensions, so you just have to disable the table extensions in the pandoc command and it should automatically convert tables to HTML. Like so: |
Beta Was this translation helpful? Give feedback.
-
The filter and the However, I've noticed one thing: both solutions write the tables like so: Bla bla bla.
<table>
<colgroup>
<col style="width: 33%" />
<col style="width: 33%" />
<col style="width: 33%" />
</colgroup>
<thead>
<tr class="header">
<th>1</th>
<th>2</th>
<th>3</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
</tbody>
</table>
Bla bla bla I.e., there are no rawBlock markers, and without those the table will not be picked up by this filter: function RawBlock (raw)
return raw.format:match 'html'
and pandoc.read(raw.text, 'html').blocks
or raw
end Further processing only works with this: Bla bla bla.
~~~{=html}
<table>
<colgroup>
<col style="width: 33%" />
<col style="width: 33%" />
<col style="width: 33%" />
</colgroup>
<thead>
<tr class="header">
<th>1</th>
<th>2</th>
<th>3</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
</tbody>
</table>
~~~
Bla bla bla Is there a way to get these rawBlock attributes automatically? |
Beta Was this translation helpful? Give feedback.
-
When converting docx to Markdown, us it possible to use Html for the tables? I'm having tables where the Markdown table syntax is hard to read, and I'd prefer to work with html tables.
Beta Was this translation helpful? Give feedback.
All reactions