-- Remove standalone Obsidian `$$` wrapper paragraphs that surround LaTeX
-- display environments. Pandoc already parses the inner environment as math,
-- so these delimiters only survive as literal text in the output.

local function clean_wrapper_block(el)
    local filtered = pandoc.List()

    for _, inline in ipairs(el.content) do
        if not (inline.t == "Str" and inline.text:match("^%s*%$%$%s*$")) then
            filtered:insert(inline)
        end
    end

    if #filtered == 0 then
        return {}
    end

    return pandoc.Para(filtered)
end

function Para(el)
    return clean_wrapper_block(el)
end

function Plain(el)
    return clean_wrapper_block(el)
end
