Rendering callouts similarly in Pandoc

Things I have tried

I have tried to find answers for my questions both here and in Google searches, but I’m not finding anything quickly.

What I’m trying to do

I will need on occasion to output my notes to PDF or other format. I would like clickable links (including a clickable table of contents) which the built-in export does not provide, but pandoc does provide. But I am noticing that the callouts which are rendered very nicely in Obsidian are not rendered well in Pandoc. What do I need to do to get Pandoc to render the markdown for callouts appropriately?

1 Like

Perhaps my question is not clear. Let me try again.

I am using Pandoc instead of the native export to PDF function because I need clickable links in my PDF documents (which is currently not available in the export to PDF function). But a drawback of doing that appears to be that the callouts which the export to PDF does nicely does not render well under Pandoc.

My question is how to get Pandoc to render the markdown for callouts well?

1 Like

I understood your question but I have no ideas on how to help! :frowning: My guess is that the issue is that Obsidian’s callouts are not part of the standard markdown specification that Pandoc knows. Is it treating them as blockquotes? I am sure there is some way to configure this; hopefully someone on this forum knows how to configure Pandoc! If not, you could try the Pandoc plugin Github repository (Discussions tab if there is one, otherwise Issues tab), or the Obsidian Discord (which I am told has a number of academics using pandoc).

1 Like

Thanks! :slight_smile: I know that sometimes how I phrase a question makes sense in my head, but maybe not always as clear to someone else.

What you have said matches what I am seeing through Google searches. There doesn’t seem to be any information on the Pandoc website or elsewhere. Hmm. My guess at the moment is that it is maybe too new a feature, but I’m not sure if that just means it will be supported if I’m patient enough or if I just need to preprocess it somehow. Now I’m wondering if an interim solution is to style it with Latex or style it with HTML just to have something that I can use. Hmm.

1 Like

You can browse the GitHub repository for the plugin without needing a GitHub account - that might give you a sense of whether things in general, or this issue in particular, are being worked on.

If you end up writing something of your own, please do post back here to share it with us! :slight_smile: Good luck!

1 Like

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 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.)

3 Likes

Very cool! I will look into this. I have not had a chance to do that yet. I did a quick and dirty Python script that reformatted some things for Pandoc, but it requires me to run a separate process. I will try this out. :slight_smile: