Tag obsidian

1 bookmark has this tag.

2024-08-14

288.

Rendering callouts similarly in Pandoc - Help - Obsidian Forum

forum.obsidian.md/t/rendering-callouts-similarly-in-pandoc/40020

Obsidian callout blocks are not part of the Pandoc Markdown syntax. But since they are kind of extended block quote syntax, you can write a Pandoc Lua filter 76 to convert them to anything you want.

Below a quick-and-dirty solution which converts Obsidian callout blocks

> [!NOTE]- Note Title
>
> Note content

to Pandoc’s native Divs

::: {.callout data-callout="note" title="Note Title"}
Note content
:::

with the following Pandoc command:

pandoc -t markdown --lua-filter obsidian-callouts.lua file.md

Important: Please note, that in order for this simple filter to work properly, callout type and title line should occupy a separate paragraph.

Here the content of the obsidian-callouts.lua file:

local stringify = (require "pandoc.utils").stringify

function BlockQuote (el)
    start = el.content[1]
    if (start.t == "Para" and start.content[1].t == "Str" and
        start.content[1].text:match("^%[!%w+%][-+]?$")) then
        _, _, ctype = start.content[1].text:find("%[!(%w+)%]")
        el.content:remove(1)
        start.content:remove(1)
        div = pandoc.Div(el.content, {class = "callout"})
        div.attributes["data-callout"] = ctype:lower()
        div.attributes["title"] = stringify(start.content):gsub("^ ", "")
        return div
    else
        return el
    end
end

You can modify it to convert callout blocks depending on the output format (HTML, LaTeX, etc.)