Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 58 additions & 7 deletions src/resources/filters/customnodes/floatreftarget.lua
Original file line number Diff line number Diff line change
Expand Up @@ -787,14 +787,65 @@ end, function(float)
float.identifier)
end

float.caption_long.content:insert(1, pandoc.RawInline("asciidoc", ". "))
float.caption_long.content:insert(pandoc.RawInline("asciidoc", "\n[[" .. float.identifier .. "]]\n===="))
return pandoc.Div({
float.caption_long,
-- pandoc.RawBlock("asciidoc", "[[" .. float.identifier .. "]]\n====\n"),
float.content,
pandoc.RawBlock("asciidoc", "====\n\n")
if float.type == "Table" and float.content.t == "Table" then
-- special-case the situation where the figure is Table and the content is Table
--
-- just return the table itself with the caption inside the table
float.content.caption.long = float.caption_long
float.content.attr = pandoc.Attr(float.identifier, float.classes or {}, float.attributes or {})
return pandoc.Blocks({
pandoc.RawBlock("asciidoc", "[[" .. float.identifier .. "]]\n"),
float.content
})
end

-- if this is a "linked figure Div", render it as such.
local link = quarto.utils.match("Plain/[1]/{Link}/[1]/{Image}")(float.content)
if link then
link[2].identifier = float.identifier
local caption = quarto.utils.as_inlines(float.caption_long)
table.insert(caption, 1, pandoc.RawInline("asciidoc", "."))
table.insert(caption, pandoc.RawInline("asciidoc", "\n[[" .. float.identifier .. "]]\n"))
table.insert(caption, link[1])
return caption
end

-- if the float consists of exactly one image,
-- render it as a pandoc Figure node.
local count = 0
local img
_quarto.ast.walk(float.content, {
Image = function(node)
count = count + 1
img = node
end
})
if count == 1 then
print(float.content)
img.identifier = float.identifier
img.caption = quarto.utils.as_inlines(float.caption_long)
return pandoc.Figure(
{img},
{float.caption_long},
float.identifier)
end

-- Fallthrough case, render into a div.
float.caption_long.content:insert(1, pandoc.RawInline("asciidoc", "."))
float.caption_long.content:insert(pandoc.RawInline("asciidoc", "\n[[" .. float.identifier .. "]]\n===="))

if pandoc.utils.type(float.content) == "Blocks" then
float.content:insert(1, float.caption_long)
float.content:insert(pandoc.RawBlock("asciidoc", "====\n"))
return float.content
else
return pandoc.Blocks({
float.caption_long,
-- pandoc.RawBlock("asciidoc", "[[" .. float.identifier .. "]]\n====\n"),
float.content,
pandoc.RawBlock("asciidoc", "====\n\n")
})
end

end)

Expand Down
3 changes: 2 additions & 1 deletion src/resources/filters/layout/asciidoc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,12 @@ end, function(layout)
end

-- this is exceedingly hacky, but it works.
-- It will fail if the caption contains citations that need to be resolved...
local caption_str = pandoc.write(pandoc.Pandoc({layout.float.caption_long}), "asciidoc")

-- we need to recurse into render_extended_nodes here, sigh
local content_str = pandoc.write(_quarto.ast.walk(pandoc.Pandoc(panel_content), render_extended_nodes()) or {}, "asciidoc")
local figure_str = ". " .. caption_str .. "[#" .. layout.identifier .. "]\n" .. content_str
local figure_str = "." .. caption_str .. "[#" .. layout.identifier .. "]\n" .. content_str

local pt = pandoc.utils.type(layout.preamble)
if pt == "Blocks" then
Expand Down
1 change: 0 additions & 1 deletion src/resources/filters/normalize/parsehtml.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ function parse_html_tables()
local htmlTableProcessing = div.attributes[constants.kHtmlTableProcessing]
div.attributes[constants.kHtmlTableProcessing] = nil
if htmlTableProcessing == "none" then
quarto.log.output(div.attr == pandoc.Attr())
if div.attr == pandoc.Attr() then
-- if no other attributes are set on the div, don't keep it
return div.content, false
Expand Down
1 change: 0 additions & 1 deletion src/resources/filters/quarto-post/foldcode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ function fold_code_and_lift_codeblocks()
return nil, false
end,
CodeBlock = function(block)
print("walking code block")
local folded_block = render_folded_block(block)
if block.classes:includes("code-annotation-code") then
print("found code annotation code block")
Expand Down
13 changes: 13 additions & 0 deletions tests/docs/smoke-all/2024/01/03/8055-b.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: Caption
format: asciidoc
---

::: {#fig-try}

![Test](surus.png)

![Test2](surus.png)

Hello
:::
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ _quarto:
asciidoc:
ensureFileRegexMatches:
-
- "\\. Customers _query_"
- "\\.Customers _query_"
- "<<lst-customers>>"
- "\\[\\[lst-customers\\]\\]"
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ _quarto:
- "\\[#fig-plots\\]"
- "\\[#fig-plots-1\\]"
- "\\[#fig-plots-2\\]"
- "\\. Plots"
- "\\.Plots"
- "\\.Plot 1"
- "\\.Plot 2"
- []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ _quarto:
- "\\[\\[tbl-cars\\]\\]"
- "\\[\\[tbl-pressure\\]\\]"
- "\\[#tbl-tables\\]" # TODO understand the difference between [[foo]] and [#foo]. From my reading of the asciidoc docs it seems ok but we should double-check.
- "\\. Tables"
- "\\. Cars"
- "\\. Pressure"
- "\\.Tables"
- "\\.Cars"
- "\\.Pressure"
- []
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ _quarto:
-
- "<<lst-customers>>"
- "\\[\\[lst-customers\\]\\]"
- "\\. Customers Query"
- "\\.Customers Query"
---

```{#lst-customers .sql lst-cap="Customers Query"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ _quarto:
-
- "\\.Surus"
- "\\.Abbas"
- "\\. Famous Elephants" # TODO We should try to understand why some captions have spaces in front of them and others don't
- "\\.Famous Elephants"
- "\\[#fig-elephants\\]"
- "\\[#fig-surus\\]"
- "\\[#fig-abbas\\]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ _quarto:
asciidoc:
ensureFileRegexMatches:
-
- "\\. This is a caption\\."
- "\\.This is a caption\\."
- "<<tbl-1>>"
- "\\[\\[tbl-1\\]\\]"
- []
Expand Down