Path: blob/main/src/resources/extensions/quarto/confluence/publish.lua
12923 views
local confluence = require('overrides')12-- From https://stackoverflow.com/questions/9168058/how-to-dump-a-table-to-console3function dumpObject(o)4if type(o) == 'table' then5local s = '{ '6for k,v in pairs(o) do7if type(k) ~= 'number' then k = '"'..k..'"' end8s = s .. '['..k..'] = ' .. dumpObject(v) .. ','9end10return s .. '} '11else12return tostring(o)13end14end1516function log(label, object)17print(label or '' .. ': ', dumpObject(object))18end192021local function injectAnchor(element, addToFront)22if(element and element.identifier and #element.identifier > 0) then23local content = element.content24-- Confluence HTML anchors are CSF macro snippets, inject into contents25local anchor = pandoc.RawInline('html', confluence.HTMLAnchorConfluence(element.identifier))26if (addToFront) then27table.insert(content, 1, anchor)28else29table.insert(content, anchor)30end31element.content = content32end33return element34end3536quarto._quarto.ast.add_renderer("Callout", function(_)37return quarto._quarto.format.isConfluenceOutput()38end, function(callout)39local renderedCalloutContent =40pandoc.write(pandoc.Pandoc(callout.content), "html", { wrap_text = "none" })41local renderString = confluence.CalloutConfluence(42callout.type,43renderedCalloutContent)44return pandoc.RawInline('html', renderString)45end)4647function Writer (doc, opts)48local filter = {49Image = function (image)50local renderString = confluence.CaptionedImageConfluence(51image.src,52image.title,53pandoc.utils.stringify(image.caption),54image.attributes,55image.identifier)56result = pandoc.RawInline('html', renderString)57return result58end,59Link = function (link)60local renderedLinkContent =61pandoc.write(pandoc.Pandoc(link.content), "html")6263source = renderedLinkContent6465local renderString = confluence.LinkConfluence(66source,67link.target,68link.title,69link.attributes)70return pandoc.RawInline('html', renderString)71end,72Div = function (div)73div = injectAnchor(div, true)74return div75end,76CodeBlock = function (codeBlock)77local renderString = confluence.CodeBlockConfluence(78codeBlock.text,79codeBlock.classes[1] or '')80return pandoc.RawBlock('html', renderString)81end,82Table = function (table)83-- Grid tables add a width style that widens the table, remove it84table.attributes.style = ""85local head = table.head86local caption = table.caption.long8788-- Captions placed inside of the table will throw an error with CSF89table.caption = {}90return { table } .. caption91end,92Block = function (block)93block = injectAnchor(block)94return block95end,96RawBlock = function (rawBlock)97-- We just "pass-through" raw blocks of type "confluence"98if(rawBlock.format == 'confluence') then99return pandoc.RawBlock('html', rawBlock.text)100end101102-- Raw blocks including arbirtary HTML like JavaScript are not supported in CSF103return ""104end,105RawInline = function (inline)106local renderString = confluence.RawInlineConfluence(inline.text)107return pandoc.RawInline('html', renderString)108end109}110111opts = opts or {}112opts.wrap_text = "none"113114local result = quarto._quarto.ast.writer_walk(doc, filter)115return pandoc.write(result, 'html', opts)116end117118119