Skip to content

mermaid + superfences + attr_list = no attributes applied to <div> #2841

@priiduonu

Description

@priiduonu

Description

I want to apply an #id to mermaid diagrams via attr_list so that I can link to them.

For example:

```mermaid {#fig:flowchart .myclass}
flowchart LR
    A[Hard edge] -->|Link text| B(Round edge)
    B --> C{Decision}
    C -->|One| D[Result one]
    C -->|Two| E[Result two]
```

See the [diagram](#fig:flowchart) above...

Result:

The #fig:flowchart does not appear anywhere in DOM and I can not link to the diagram.

In resulting HTML the diagram is wrapped in:

<div class="mermaid">
...
</div>

but no custom attributes (id and class) are applied to the <div>.

I know I can wrap the code block in <div> but as I'm further processing the input with pandoc + crossref to LaTeX, I would have to apply the attributes for the code block as well and it is cumbersome to keep them in sync.

Tried with both MkDocs and Zensical, both give the same result.

Is it possible to apply the attributes as above and I'm doing something wrong or is this the expected result?

Minimal Reproduction

The relevant section from mkdocs.yml:

markdown_extensions:
    - attr_list
    - pymdownx.superfences:
        custom_fences:
          - name: mermaid
            class: mermaid
            format: !!python/name:pymdownx.superfences.fence_code_format

Additionally:

When I change the fence_code_format to fence_div_format, the custom attributes are applied to the <div> but obviously the diagram is not rendered as image.

Version(s) & System Info

  • Operating System: ...
  • Python Version: ...
  • Package Version: ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions