Skip to content

How to create custom superfences formatter? #928

@Zebradil

Description

@Zebradil

I was looking through the uml-diagram-example, but I can't figure out how to implement custom formatter instead of using one of the default ones.

In the example, processing is done by mermaid library on the client side. Instead, I want to process content of a superfenced block on backend during mkdocs build.

That's what I have in my config file:

markdown_extensions:
  ...
  - pymdownx.superfences
      custom_fences:
        - name: graphviz
          class: graphviz
          format: !!python/name:<custom formatter function>

In the docs there is an example format function:

def custom_format(source, language, class_name, options, md):
    """Custom format."""

    return '<div class_name="%s %s", data-option="%s">%s</div>' % (language, class_name, options['opt'], html_escape(source))

Where should I put it?

Should I now create a new python module and install it or it's possible to access python source code from local file?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions