sphinx-contrib / confluencebuilder

Confluence Markup Builder Plugin for Sphinx
BSD 2-Clause "Simplified" License
315 stars 99 forks source link

Support rendering Mermaid with raw HTML blocks #972

Closed neongreen-sc closed 1 month ago

neongreen-sc commented 4 months ago

I work in an environment where mermaid-cli is tricky to install.

However, our Confluence Server instance has HTML enabled, and for Mermaid blocks we can simply output smth like:

<script type="module">
  import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';
</script>
<pre class="mermaid">
  .. diagram goes here ..
</pre>

This would be great to support natively.

neongreen-sc commented 4 months ago

For now my workaround is to disable mermaid processing in confluencebuilder and process <mermaid> nodes in a separate pass.

jdknight commented 4 months ago

Does the confluence_permit_raw_html option work for this use case?

neongreen-sc commented 4 months ago

Without confluence_permit_raw_html: confluencebuilder's mermaid override kicks in and says that it can't run mmdc.

With confluence_permit_raw_html and confluence_adv_restricted = ["ext-sphinxcontrib.mermaid"]: mermaid nodes aren't touched at all and we end up with "unknown node type: mermaid".

I haven't tried with confluence_permit_raw_html but without confluence_adv_restricted -- is it supposed to work? I would guess not.

jdknight commented 4 months ago

Sorry, I was under the assumption that you may have already hooked into sphinxcontrib-mermaid's implementation to have the HTML content generated for you. If you did something like this:

from sphinxcontrib.mermaid import html_visit_mermaid
from sphinxcontrib.mermaid import mermaid
...
def setup(app: Sphinx):
    app.add_node(mermaid, confluence=(html_visit_mermaid, None))

This could inject HTML into the body document that may work with confluence_adv_restricted enabled.

jdknight commented 1 month ago

Changes from #1037 should help support this through a new confluence_mermaid_html_macro option.

jdknight commented 1 month ago

v2.7 is now available on PyPI -- marking as closed.