diff --git a/src/resources/filters/customnodes/floatreftarget.lua b/src/resources/filters/customnodes/floatreftarget.lua index e110b3fe9f2..77e0df3a30e 100644 --- a/src/resources/filters/customnodes/floatreftarget.lua +++ b/src/resources/filters/customnodes/floatreftarget.lua @@ -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) diff --git a/src/resources/filters/layout/asciidoc.lua b/src/resources/filters/layout/asciidoc.lua index 16acd30fdee..f968f4b50d7 100644 --- a/src/resources/filters/layout/asciidoc.lua +++ b/src/resources/filters/layout/asciidoc.lua @@ -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 diff --git a/src/resources/filters/normalize/parsehtml.lua b/src/resources/filters/normalize/parsehtml.lua index 127f34f169c..c9837b01e88 100644 --- a/src/resources/filters/normalize/parsehtml.lua +++ b/src/resources/filters/normalize/parsehtml.lua @@ -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 diff --git a/src/resources/filters/quarto-post/foldcode.lua b/src/resources/filters/quarto-post/foldcode.lua index c521b5e22ee..67de3d8b7af 100644 --- a/src/resources/filters/quarto-post/foldcode.lua +++ b/src/resources/filters/quarto-post/foldcode.lua @@ -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") diff --git a/tests/docs/smoke-all/2024/01/03/8055-b.qmd b/tests/docs/smoke-all/2024/01/03/8055-b.qmd new file mode 100644 index 00000000000..7eb820d0ea4 --- /dev/null +++ b/tests/docs/smoke-all/2024/01/03/8055-b.qmd @@ -0,0 +1,13 @@ +--- +title: Caption +format: asciidoc +--- + +::: {#fig-try} + +![Test](surus.png) + +![Test2](surus.png) + +Hello +::: \ No newline at end of file diff --git a/tests/docs/smoke-all/crossrefs/float/asciidoc/asciidoc-float-caption-formatting-1.qmd b/tests/docs/smoke-all/crossrefs/float/asciidoc/asciidoc-float-caption-formatting-1.qmd index 1875bd14e78..aa91f501746 100644 --- a/tests/docs/smoke-all/crossrefs/float/asciidoc/asciidoc-float-caption-formatting-1.qmd +++ b/tests/docs/smoke-all/crossrefs/float/asciidoc/asciidoc-float-caption-formatting-1.qmd @@ -6,7 +6,7 @@ _quarto: asciidoc: ensureFileRegexMatches: - - - "\\. Customers _query_" + - "\\.Customers _query_" - "<>" - "\\[\\[lst-customers\\]\\]" --- diff --git a/tests/docs/smoke-all/crossrefs/float/asciidoc/asciidoc-jupyter-2.qmd b/tests/docs/smoke-all/crossrefs/float/asciidoc/asciidoc-jupyter-2.qmd index 00c861e0954..0713791d2de 100644 --- a/tests/docs/smoke-all/crossrefs/float/asciidoc/asciidoc-jupyter-2.qmd +++ b/tests/docs/smoke-all/crossrefs/float/asciidoc/asciidoc-jupyter-2.qmd @@ -10,7 +10,7 @@ _quarto: - "\\[#fig-plots\\]" - "\\[#fig-plots-1\\]" - "\\[#fig-plots-2\\]" - - "\\. Plots" + - "\\.Plots" - "\\.Plot 1" - "\\.Plot 2" - [] diff --git a/tests/docs/smoke-all/crossrefs/float/asciidoc/asciidoc-knitr-table-captions-1.qmd b/tests/docs/smoke-all/crossrefs/float/asciidoc/asciidoc-knitr-table-captions-1.qmd index f18a8f7a582..cb28c0b3989 100644 --- a/tests/docs/smoke-all/crossrefs/float/asciidoc/asciidoc-knitr-table-captions-1.qmd +++ b/tests/docs/smoke-all/crossrefs/float/asciidoc/asciidoc-knitr-table-captions-1.qmd @@ -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" - [] --- diff --git a/tests/docs/smoke-all/crossrefs/float/asciidoc/asciidoc-listings-1.qmd b/tests/docs/smoke-all/crossrefs/float/asciidoc/asciidoc-listings-1.qmd index 453b7677c3b..3f47a80b9ba 100644 --- a/tests/docs/smoke-all/crossrefs/float/asciidoc/asciidoc-listings-1.qmd +++ b/tests/docs/smoke-all/crossrefs/float/asciidoc/asciidoc-listings-1.qmd @@ -8,7 +8,7 @@ _quarto: - - "<>" - "\\[\\[lst-customers\\]\\]" - - "\\. Customers Query" + - "\\.Customers Query" --- ```{#lst-customers .sql lst-cap="Customers Query"} diff --git a/tests/docs/smoke-all/crossrefs/float/asciidoc/asciidoc-subfloat-1.qmd b/tests/docs/smoke-all/crossrefs/float/asciidoc/asciidoc-subfloat-1.qmd index 15ec1759a7c..405be6be56c 100644 --- a/tests/docs/smoke-all/crossrefs/float/asciidoc/asciidoc-subfloat-1.qmd +++ b/tests/docs/smoke-all/crossrefs/float/asciidoc/asciidoc-subfloat-1.qmd @@ -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\\]" diff --git a/tests/docs/smoke-all/crossrefs/float/asciidoc/rawtablecaption.qmd b/tests/docs/smoke-all/crossrefs/float/asciidoc/rawtablecaption.qmd index 6079104ce5f..2ea1a4981d7 100644 --- a/tests/docs/smoke-all/crossrefs/float/asciidoc/rawtablecaption.qmd +++ b/tests/docs/smoke-all/crossrefs/float/asciidoc/rawtablecaption.qmd @@ -6,7 +6,7 @@ _quarto: asciidoc: ensureFileRegexMatches: - - - "\\. This is a caption\\." + - "\\.This is a caption\\." - "<>" - "\\[\\[tbl-1\\]\\]" - []