Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/resources/extensions/quarto/confluence/publish.lua
12923 views
1
local confluence = require('overrides')
2
3
-- From https://stackoverflow.com/questions/9168058/how-to-dump-a-table-to-console
4
function dumpObject(o)
5
if type(o) == 'table' then
6
local s = '{ '
7
for k,v in pairs(o) do
8
if type(k) ~= 'number' then k = '"'..k..'"' end
9
s = s .. '['..k..'] = ' .. dumpObject(v) .. ','
10
end
11
return s .. '} '
12
else
13
return tostring(o)
14
end
15
end
16
17
function log(label, object)
18
print(label or '' .. ': ', dumpObject(object))
19
end
20
21
22
local function injectAnchor(element, addToFront)
23
if(element and element.identifier and #element.identifier > 0) then
24
local content = element.content
25
-- Confluence HTML anchors are CSF macro snippets, inject into contents
26
local anchor = pandoc.RawInline('html', confluence.HTMLAnchorConfluence(element.identifier))
27
if (addToFront) then
28
table.insert(content, 1, anchor)
29
else
30
table.insert(content, anchor)
31
end
32
element.content = content
33
end
34
return element
35
end
36
37
quarto._quarto.ast.add_renderer("Callout", function(_)
38
return quarto._quarto.format.isConfluenceOutput()
39
end, function(callout)
40
local renderedCalloutContent =
41
pandoc.write(pandoc.Pandoc(callout.content), "html", { wrap_text = "none" })
42
local renderString = confluence.CalloutConfluence(
43
callout.type,
44
renderedCalloutContent)
45
return pandoc.RawInline('html', renderString)
46
end)
47
48
function Writer (doc, opts)
49
local filter = {
50
Image = function (image)
51
local renderString = confluence.CaptionedImageConfluence(
52
image.src,
53
image.title,
54
pandoc.utils.stringify(image.caption),
55
image.attributes,
56
image.identifier)
57
result = pandoc.RawInline('html', renderString)
58
return result
59
end,
60
Link = function (link)
61
local renderedLinkContent =
62
pandoc.write(pandoc.Pandoc(link.content), "html")
63
64
source = renderedLinkContent
65
66
local renderString = confluence.LinkConfluence(
67
source,
68
link.target,
69
link.title,
70
link.attributes)
71
return pandoc.RawInline('html', renderString)
72
end,
73
Div = function (div)
74
div = injectAnchor(div, true)
75
return div
76
end,
77
CodeBlock = function (codeBlock)
78
local renderString = confluence.CodeBlockConfluence(
79
codeBlock.text,
80
codeBlock.classes[1] or '')
81
return pandoc.RawBlock('html', renderString)
82
end,
83
Table = function (table)
84
-- Grid tables add a width style that widens the table, remove it
85
table.attributes.style = ""
86
local head = table.head
87
local caption = table.caption.long
88
89
-- Captions placed inside of the table will throw an error with CSF
90
table.caption = {}
91
return { table } .. caption
92
end,
93
Block = function (block)
94
block = injectAnchor(block)
95
return block
96
end,
97
RawBlock = function (rawBlock)
98
-- We just "pass-through" raw blocks of type "confluence"
99
if(rawBlock.format == 'confluence') then
100
return pandoc.RawBlock('html', rawBlock.text)
101
end
102
103
-- Raw blocks including arbirtary HTML like JavaScript are not supported in CSF
104
return ""
105
end,
106
RawInline = function (inline)
107
local renderString = confluence.RawInlineConfluence(inline.text)
108
return pandoc.RawInline('html', renderString)
109
end
110
}
111
112
opts = opts or {}
113
opts.wrap_text = "none"
114
115
local result = quarto._quarto.ast.writer_walk(doc, filter)
116
return pandoc.write(result, 'html', opts)
117
end
118
119