jupyter-book / mystmd

Command line tools for working with MyST Markdown.
https://mystmd.org/guide
MIT License
191 stars 62 forks source link

Tables included with `{include}` not exporting to DOCX #1275

Open roaldarbol opened 3 months ago

roaldarbol commented 3 months ago

Description

Currently, you can {include} tables into the HTML site without issues with the syntax:

::::{table} Area Comparisons (written in fancy HTML)
:label: tbl:fancy-table

:::{include} table.html
:::

::::

However, exporting to DOCX doesn't work. It generates the following errors:

❯ myst build table.md --docx --debug
...
Exporting formats: "docx"
loadFile: loaded /Users/roaldarbol/Filen/Projects/myst-tables/table.md in 44 ms.
📬 Performing exports:
   table.md -> _build/exports/table.doc
Loaded site config from /Users/roaldarbol/Filen/Projects/myst-tables/myst.yml
Loaded project config from /Users/roaldarbol/Filen/Projects/myst-tables/myst.yml
loadFile: loaded /Users/roaldarbol/Filen/Projects/myst-tables/table.md in 4.76 ms.
Processing "/Users/roaldarbol/Filen/Projects/myst-tables/table.md"
⛔️ table.md container of kind table contains no valid content besides caption, legend
   Valid content types include image, referenced notebook cell, table, code, iframe, subfigure
To suppress this message, add rule: "contianer-children-valid" to "error_rules" in your project config
⚠️  table.md unexpected figure content of type table found in legend node
To suppress this message, add rule: "contianer-children-valid" to "error_rules" in your project config
📖 Built table.md in 39 ms.
Transformed mdast cross references and links for "/Users/roaldarbol/Filen/Projects/myst-tables/table.md" in 6.02 ms
📚 Built 1 page for export (including 0 dependencies) from /Users/roaldarbol/Filen/Projects/myst-tables in 53 ms.
Template found: /Users/roaldarbol/Filen/Projects/myst-tables/_build/templates/docx/myst/default
⛔️ _build/exports/table.doc Node of type "legend" is not supported by docx renderer
To suppress this message, add rule: "docx-renders" to "error_rules" in your project config
📄 Exported DOCX in 199 ms, copying to _build/exports/table.doc

Additional notes

A minimal reproducible example:

  1. Save as table.html:

    <table>
    <tr>
       <th rowspan="2">Projection</th>
       <th colspan="3" align="center">Area in square miles</th>
    </tr>
    <tr>
       <th align="right">Large Horizontal Area</th>
       <th align="right" style="background: -webkit-linear-gradient(20deg, #09009f, #E743D9); -webkit-background-clip: text; -webkit-text-fill-color: transparent;">Large Vertical Area</th>
       <th align="right">Smaller Square Area
       <th>
    </tr>
    <tr>
       <td>Albers Equal Area</td>
       <td align="right">7,498.7</td>
       <td align="right">10,847.3</td>
       <td align="right">35.8</td>
    </tr>
    <tr>
       <td>Web Mercator</td>
       <td align="right">13,410.0</td>
       <td align="right">18,271.4</td>
       <td align="right">63.0</td>
    </tr>
    <tr>
       <td>Difference</td>
       <td align="right" style="background-color: red;color: white">5,911.3</td>
       <td align="right">7,424.1</td>
       <td align="right">27.2</td>
    </tr>
    <tr>
       <td>
          <bold>Percent Difference</bold>
       </td>
       <td align="right" style="background-color: green;color: white">44%</td>
       <td align="right">41%</td>
       <td align="right">43%</td>
    </tr>
    </table>
  2. Save as tables.md:

    
    ---
    title: Testing tables
    ---
    ::::{table} Area Comparisons (written in fancy HTML)
    :label: tbl:areas-html

:::{include} table.html :::

::::



3. Build DOCX file:
`myst build table.md --docx --debug`
roaldarbol commented 3 months ago

It seems that export to PDF through Typst is also broken.

Screenshot 2024-06-10 at 12 08 29