Skip to content

Commit 59ab1c2

Browse files
committed
Handle asciidoc figures
1 parent 968f97a commit 59ab1c2

File tree

7 files changed

+44
-0
lines changed

7 files changed

+44
-0
lines changed

src/format/asciidoc/format-asciidoc.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export function asciidocFormat(): Format {
5252
plaintextFormat("Asciidoc", "adoc"),
5353
{
5454
pandoc: {
55+
// This is required because Pandoc is wrapping asciidoc images which must be on one line
56+
wrap: "none",
5557
template: formatResourcePath(
5658
"asciidoc",
5759
join(

src/resources/filters/crossref/figures.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ function processFigure(el, captionContent)
4444
tprepend(captionContent, {
4545
pandoc.RawInline('latex', '\\label{' .. label .. '}')
4646
})
47+
elseif _quarto.format.isAsciiDocOutput() then
48+
el.attr.identifier = label
4749
else
4850
tprepend(captionContent, figureTitlePrefix(order))
4951
end

src/resources/filters/crossref/refs.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ function resolveRefs()
6767
-- for latex inject a \ref, otherwise format manually
6868
if _quarto.format.isLatexOutput() then
6969
ref:extend({pandoc.RawInline('latex', '\\ref{' .. label .. '}')})
70+
elseif _quarto.format.isAsciiDocOutput() then
71+
ref:extend({pandoc.RawInline('asciidoc', '<<' .. label .. '>>')})
7072
else
7173
if not resolve then
7274
local refClasses = pandoc.List({"quarto-unresolved-ref"})
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-- asciidoc.lua
2+
-- Copyright (C) 2020-2022 Posit Software, PBC
3+
4+
function asciidocFigure(image)
5+
local renderedCaption = pandoc.write(pandoc.Pandoc({image.caption}))
6+
return pandoc.RawBlock("asciidoc", "." .. renderedCaption .. "\n[#" .. image.attr.identifier .. "]\nimage::" .. image.src .. "[]" )
7+
end
8+
9+
function asciidocDivFigure(el)
10+
11+
local figure = pandoc.List({})
12+
local id = el.attr.identifier
13+
14+
-- append everything before the caption
15+
local contents = tslice(el.content, 1, #el.content - 1)
16+
17+
-- return the figure and caption
18+
local caption = refCaptionFromDiv(el)
19+
if not caption then
20+
caption = pandoc.Inlines()
21+
end
22+
local renderedCaption = pandoc.write(pandoc.Pandoc({caption}), "asciidoc")
23+
24+
figure:insert(pandoc.RawBlock('asciidoc', '.' .. renderedCaption))
25+
figure:insert(pandoc.RawBlock('asciidoc', '[#' .. id .. ']\n'))
26+
tappend(figure, contents)
27+
return figure
28+
end

src/resources/filters/layout/figures.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ function extendedFigures()
1414
return latexImageFigure(image)
1515
elseif _quarto.format.isDocxOutput() then
1616
return wpDivFigure(createFigureDiv(el, image))
17+
elseif _quarto.format.isAsciiDocOutput() then
18+
return asciidocFigure(image)
1719
end
1820
end
1921
end,
@@ -28,6 +30,8 @@ function extendedFigures()
2830
return wpDivFigure(el)
2931
elseif _quarto.format.isJatsOutput() then
3032
return jatsDivFigure(el)
33+
elseif _quarto.format.isAsciiDocOutput() then
34+
return asciidocDivFigure(el)
3135
end
3236
end
3337
end

src/resources/filters/main.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ import("./normalize/normalize.lua")
8484
import("./normalize/parsehtml.lua")
8585
import("./normalize/extractquartodom.lua")
8686

87+
import("./layout/asciidoc.lua")
8788
import("./layout/meta.lua")
8889
import("./layout/width.lua")
8990
import("./layout/latex.lua")

src/resources/pandoc/datadir/_format.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ local function isLatexOutput()
3030
return FORMAT == "latex" or FORMAT == "beamer" or FORMAT == "pdf"
3131
end
3232

33+
local function isAsciiDocOutput()
34+
return FORMAT == "asciidoc"
35+
end
36+
3337
local function isBeamerOutput()
3438
return FORMAT == "beamer"
3539
end
@@ -193,6 +197,7 @@ end
193197

194198

195199
return {
200+
isAsciiDocOutput = isAsciiDocOutput,
196201
isRawHtml = isRawHtml,
197202
isRawLatex = isRawLatex,
198203
isFormat = isFormat,

0 commit comments

Comments
 (0)