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

Lua Filters

Lua Filters

The final component that can help you customize your experience with Zettlr are custom Lua Filters. You can view and modify Lua filters in the assets manager.

assets_manager_lua_filter.png

What is a Lua Filter?

A Lua Filter is a small program that you can write to customize how Pandoc exports your documents. They are written using the Lua scripting language and Pandoc supports them natively.

Indeed, Zettlr already ships with two built-in filters – one for wiki links, and one for tags!

Lua filters run during the export stage and can modify any document before Pandoc actually writes the file contents to disk. This can allow you to customize how your documents are transformed from simple additions (e.g., removing tags) to large changes to the syntax tree (e.g., by transforming Mermaid code blocks to actual Mermaid diagrams).

Lua is a powerful language, and Pandoc’s integration with them is deep. This documentation is not the right place to explain everything about Lua to you.

Instead, we kindly refer you to Pandoc’s extensive documentation on how to write your own Lua filters.

Lua Filters for Zettlr: Best Practices

While Zettlr is happy about any Lua filter written for Pandoc, there are a few caveats to consider. First, Zettlr will always run all filters in your filter directory. So every filter you can see in the assets manager will always run for every export.

This means that, instead of assuming a certain document structure, Zettlr’s Lua filters are intended to run conditionally.

In fact, the workflow guide already gives a hint at how this works: Upon export, Zettlr will write into your profile’s metadata some configuration settings that the two built-in filters for links and tags read.

Whenever the metadata of any document includes the option zettlr.strip_links, for example, the filter will read this setting, and transform the document as applicable.

In the link filter, for example, this is how it looks:

Meta = function (meta)
  -- Retrieve the option required for this filter if they exist.
  if meta.zettlr then
    if meta.zettlr.strip_links then
      strip_links = meta.zettlr.strip_links
    end
  end
  return meta
end

The filter will then check every link and either do nothing (if you set your preference to leave wiki links as they are in your settings), or adjust the link according to your preference. This way, the filter can run every time, but depends on your settings.

You may want to do something similar for your filters: Define a configuration option that must be set in order for the filter to run. This way, your program can decide if it needs to run based on an entry in your YAML front matter.

If you were to manually set the option strip links in your front matter, it might look as follows:

---
zettlr:
  strip_links: "no"
---
Edit on GitHub
Last update: 8/4/26, 2:35 PM
Contributors: Hendrik Erz
Prev
Printing and Previewing
Next
PKMS/Zettelkasten
© 2017-2026 by Zettlr and Contributors