Zum Inhalt

Hinweis: Diese Inhalte wurden mit Unterstützung von Künstlicher Intelligenz erstellt und redaktionell überprüft (Transparenzhinweis gemäß Art. 50 EU AI Act).

Praxis-Guide: Pandoc Custom Lua-Filter

Pandoc Lua-Filter erlauben die direkte Manipulation des Abstract Syntax Trees (AST) von Markdown-Dokumenten beim Konvertieren zu PDF, HTML oder DOCX.


-- red_links.lua
function Link(el)
    if el.target:match("^http") then
        return pandoc.Span(el.content, {style = "color: red;"})
    end
    return el
end

🛠️ 2. Beispiel 2: Verwandlung von Hinweisen in Callout-Boxen (callouts.lua)

-- callouts.lua
function BlockQuote(el)
    -- Prüft ob das Zitat mit [!NOTE] beginnt
    local first_block = el.content[1]
    if first_block and first_block.t == "Paragraph" then
        local first_inline = first_block.content[1]
        if first_inline and first_inline.t == "Str" and first_inline.text == "[!NOTE]" then
            table.remove(first_block.content, 1) # Entferne den Tag
            return pandoc.Div(el.content, {class = "admonition note"})
        end
    end
    return el
end

⚡ 3. Lua-Filter anwenden

pandoc input.md --lua-filter=red_links.lua --lua-filter=callouts.lua -o output.pdf --pdf-engine=typst

🔗 Verwandte Themen

Hinweis: Diese Inhalte wurden mit Unterstützung von Künstlicher Intelligenz erstellt und redaktionell überprüft (Transparenzhinweis gemäß Art. 50 EU AI Act).