Zettlr LogoZettlr Documentation
Setup
Troubleshooting
FAQ
  • About Zettlr
  • Download Zettlr
  • GitHub
  • English
  • Español
  • Deutsch
  • Français
  • Italiano
  • 日本語
  • Português
  • Русский
Setup
Troubleshooting
FAQ
  • About Zettlr
  • Download Zettlr
  • GitHub
  • English
  • Español
  • Deutsch
  • Français
  • Italiano
  • 日本語
  • Português
  • Русский
  • Welcome
  • Getting started

    • Setup
    • Migrating from Obsidian
    • Migrating to a New Computer
    • Installing LaTeX
    • A Note on Security
    • Get involved
    • Troubleshooting
  • First Time Users

    • First Steps
    • Workspaces
    • Creating Files and Folders
    • Writing Markdown
    • Importing Word- and other Documents into Zettlr
    • Exporting Files
  • Interface

    • File Manager
      • Workspaces and Root Files
      • Choosing Which Files To Display
      • File Manager Appearance (Modes)
      • The File List
      • Properties
      • Filtering
      • Global Search
      • Projects
    • Split View
      • Document Tab Bar
      • Markdown Editor
      • Code Editor
      • Image Viewer
      • PDF Viewer
    • Sidebar
      • Table of Contents
      • References
      • Related Files
      • Other Files
  • Writing

    • Markdown Editor
      • Markdown Compendium
      • Appearance
      • Search
      • Autocomplete
      • Footnotes
      • Citations
      • Working With Comments
      • Status Bar
      • Table Editor
      • Text Transforms
      • Snippets
      • YAML Front Matter
    • Language & Style
      • Spellchecking
      • LanguageTool
      • Markdown Syntax
      • Autocorrect and Magic Quotes
      • Readability
    • Scientific & Technical
      • Math
      • Code Blocks
      • Mermaid Diagrams
      • Pomodoro Timer
      • Writing Statistics
    • Exporting
      • Exporting Workflow
      • Defaults Files (Profiles)
      • Selecting the PDF Engine
      • Assets Manager
      • Custom Templates and Reference Documents
      • Custom Commands
      • Printing and Previewing
      • Lua Filters
    • PKMS & Zettelkasten
      • The Zettelkasten method
      • Graph View
      • Tag Manager
  • Guides
    • Custom CSS
    • Reference Manager Integration
    • Setting up LanguageTool locally
    • Presentations
    • Submitting to a Journal using a LaTeX Template
    • Zettlr as a Portable App
  • Reference
    • Keyboard Shortcuts
    • Settings
    • Frequently Asked Questions

Mermaid Diagrams

Mermaid Diagrams

Oftentimes, having a way to quickly draft a diagram can be useful for both scientific and technical applications. To do so, Zettlr ships with built-in support for Mermaid diagrams. Mermaid.js is an alternative to other diagram solutions such as UML or draw.io.

Mermaid diagrams use a markup language that allows you to specify the diagram, which the Mermaid engine will then render.

This means that Zettlr utilizes code blocks for creating Mermaid diagrams.

Rendering Mermaid

Zettlr can render a Mermaid-diagram in place. To do so, make sure that the corresponding renderer is active and that the rendering mode is set to “Preview,” not “raw.”

The following sample flowchart:

```mermaid
flowchart TD
    A[Christmas] -->|Get money| B(Go shopping)
    B --> C{Let me think}
    C -->|One| D[Laptop]
    C -->|Two| E[iPhone]
    C -->|Three| F[fa:fa-car Car]
```

Will render like so:

mermaid_example.png

Syntax highlighting for Mermaid diagrams is not supported.

Rendering Mermaid on Export

One difficulty with Mermaid is that, while Zettlr supports rendering Mermaid diagrams out of the box, many other systems do not. Please refer to the Mermaid documentation on how to enable diagram rendering in various contexts.

To allow Mermaid rendering when you export documents using Pandoc directly from Zettlr, you will need to use a Lua-filter to add Mermaid support.

Here follows an example filter that you could use. However, note that we do not provide support for this filter. It may stop working at any time.

To use this filter, you will need to install the Mermaid.js CLI utility (mmdc). If you need help, please ask the community, but do not open an issue on GitHub.

-- Lua filter to enable Pandoc Mermaid support during exports
local supported_formats = {
  svg = { "svg", "image/svg+xml" },
  png = { "png", "image/png" },
  pdf = { "pdf", "application/pdf" }
}

local default_formats = {
  html = supported_formats["svg"],
  latex = supported_formats["pdf"],
  beamer = supported_formats["pdf"]
}

local function get_format (format)
  if supported_formats[format] then
    return supported_formats[format]
  else
    return supported_formats["png"]
  end
end

local function render_mermaid (code, filetype, width, height, scale)
  local w = width or "800"
  local h = height or "600"
  local s = scale or "1P"
  local output = pandoc.pipe("mmdc", {
    "-e", filetype, "--width", w, "--height", h,
    "--scale", s,
    "-i", "-", "-o", "-"
  }, code)
  return output
end

function CodeBlock(block)
    if block.classes[1] == "mermaid" then
      local default_format = get_format(FORMAT)
      local filetype = default_format[1]
      local mimetype = default_format[2]
      if block.attr['format'] then
        local custom_format = get_format(block.attr['format'])
        filetype = custom_format[1]
        mimetype = custom_format[2]
      end

      local img = render_mermaid(block.text, filetype, block.attr['export_width'], block.attr['export_height'], block.attr['export_scale'])
      local fname = pandoc.sha1(img) .. "." .. filetype
      pandoc.mediabag.insert(fname, mimetype, img)
      local image = pandoc.Image({ pandoc.Str("Mermaid diagram") }, fname, "", block.attr)
      return pandoc.Figure({ image }, pandoc.Caption())
    end
end
Edit on GitHub
Last update: 12/6/25, 4:34 AM
Contributors: Hendrik Erz
Prev
Code Blocks
Next
Pomodoro Timer
© 2017-2026 by Zettlr and Contributors