diff --git a/news/changelog-1.8.md b/news/changelog-1.8.md index ec10b18d463..b28360c641c 100644 --- a/news/changelog-1.8.md +++ b/news/changelog-1.8.md @@ -40,6 +40,10 @@ All changes included in 1.8: - ([#12775](https://github.com/quarto-dev/quarto-cli/issues/12775)): Convert Quarto-native layouts (divs with `layout` syntax) to Beamer columns, equivalent to using the Pandoc-native syntax of div with `columns` and `column` classes. +### `hugo-md` + +- ([#12676](https://github.com/quarto-dev/quarto-cli/issues/12676)): Add support for rendering layout panels that are not floats. + ## Projects ### `website` diff --git a/src/resources/filters/layout/hugo.lua b/src/resources/filters/layout/hugo.lua index 88f20430223..3c73b00c927 100644 --- a/src/resources/filters/layout/hugo.lua +++ b/src/resources/filters/layout/hugo.lua @@ -4,9 +4,51 @@ _quarto.ast.add_renderer("PanelLayout", function(_) return _quarto.format.isHugoMarkdownOutput() end, function(layout) + local function make_panel_content() + local panel_content = pandoc.Blocks({}) + -- layout + for i, row in ipairs(layout.layout) do + + local aligns = row:map(function(cell) + -- get the align + local align = cell.attributes[kLayoutAlign] + return layoutTableAlign(align) + end) + local widths = row:map(function(cell) + -- propagage percents if they are provided + local layoutPercent = horizontalLayoutPercent(cell) + if layoutPercent then + return layoutPercent / 100 + else + return 0 + end + end) + + local cells = pandoc.List() + for _, cell in ipairs(row) do + cells:insert(cell) + end + + -- make the table + local panelTable = pandoc.SimpleTable( + pandoc.List(), -- caption + aligns, + widths, + pandoc.List(), -- headers + pandoc.List { cells } + ) + + -- add it to the panel + panel_content:insert(pandoc.utils.from_simple_table(panelTable)) + end + return panel_content + end + if layout.float == nil then - fail_and_ask_for_bug_report("Can't render layouts without floats") - return pandoc.Div({}) + -- if there is no float, then we just return the content and preamble + local result = pandoc.Div(layout.preamble or {}) + result.content:extend(make_panel_content()) + return result end decorate_caption_with_crossref(layout.float) @@ -14,45 +56,9 @@ end, function(layout) if not options then options = {} end - -- outer panel to contain css and figure panel - local attr = pandoc.Attr(layout.identifier or "", layout.classes or {}, layout.attributes or {}) - local panel_content = pandoc.Blocks({}) - -- layout - for i, row in ipairs(layout.layout) do - - local aligns = row:map(function(cell) - -- get the align - local align = cell.attributes[kLayoutAlign] - return layoutTableAlign(align) - end) - local widths = row:map(function(cell) - -- propagage percents if they are provided - local layoutPercent = horizontalLayoutPercent(cell) - if layoutPercent then - return layoutPercent / 100 - else - return 0 - end - end) - - local cells = pandoc.List() - for _, cell in ipairs(row) do - cells:insert(cell) - end - - -- make the table - local panelTable = pandoc.SimpleTable( - pandoc.List(), -- caption - aligns, - widths, - pandoc.List(), -- headers - { cells } - ) - - -- add it to the panel - panel_content:insert(pandoc.utils.from_simple_table(panelTable)) - end + local panel_content = make_panel_content() + -- outer panel to contain css and figure panel local result = pandoc.Div({}) -- the format for the rawblock is html and not markdown_strict -- because this might end up inside a table, and Pandoc diff --git a/tests/docs/smoke-all/2025/06/12/issue-12676.qmd b/tests/docs/smoke-all/2025/06/12/issue-12676.qmd new file mode 100644 index 00000000000..494962bc448 --- /dev/null +++ b/tests/docs/smoke-all/2025/06/12/issue-12676.qmd @@ -0,0 +1,12 @@ +--- +format: hugo-md +--- + +::: {layout-ncol="2"} + +Hello. + +Hello. + +::: +