Skip to content

Commit 487fd0e

Browse files
authored
Merge pull request #12931 from quarto-dev/bugfix/12676
hugo-md - add rendering for non-float layouts (#12676)
2 parents 75d1c60 + 331d76f commit 487fd0e

File tree

3 files changed

+62
-40
lines changed

3 files changed

+62
-40
lines changed

news/changelog-1.8.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ All changes included in 1.8:
4040

4141
- ([#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.
4242

43+
### `hugo-md`
44+
45+
- ([#12676](https://github.com/quarto-dev/quarto-cli/issues/12676)): Add support for rendering layout panels that are not floats.
46+
4347
## Projects
4448

4549
### `website`

src/resources/filters/layout/hugo.lua

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,61 @@
44
_quarto.ast.add_renderer("PanelLayout", function(_)
55
return _quarto.format.isHugoMarkdownOutput()
66
end, function(layout)
7+
local function make_panel_content()
8+
local panel_content = pandoc.Blocks({})
9+
-- layout
10+
for i, row in ipairs(layout.layout) do
11+
12+
local aligns = row:map(function(cell)
13+
-- get the align
14+
local align = cell.attributes[kLayoutAlign]
15+
return layoutTableAlign(align)
16+
end)
17+
local widths = row:map(function(cell)
18+
-- propagage percents if they are provided
19+
local layoutPercent = horizontalLayoutPercent(cell)
20+
if layoutPercent then
21+
return layoutPercent / 100
22+
else
23+
return 0
24+
end
25+
end)
26+
27+
local cells = pandoc.List()
28+
for _, cell in ipairs(row) do
29+
cells:insert(cell)
30+
end
31+
32+
-- make the table
33+
local panelTable = pandoc.SimpleTable(
34+
pandoc.List(), -- caption
35+
aligns,
36+
widths,
37+
pandoc.List(), -- headers
38+
pandoc.List { cells }
39+
)
40+
41+
-- add it to the panel
42+
panel_content:insert(pandoc.utils.from_simple_table(panelTable))
43+
end
44+
return panel_content
45+
end
46+
747
if layout.float == nil then
8-
fail_and_ask_for_bug_report("Can't render layouts without floats")
9-
return pandoc.Div({})
48+
-- if there is no float, then we just return the content and preamble
49+
local result = pandoc.Div(layout.preamble or {})
50+
result.content:extend(make_panel_content())
51+
return result
1052
end
1153
decorate_caption_with_crossref(layout.float)
1254

1355
-- empty options by default
1456
if not options then
1557
options = {}
1658
end
17-
-- outer panel to contain css and figure panel
18-
local attr = pandoc.Attr(layout.identifier or "", layout.classes or {}, layout.attributes or {})
19-
local panel_content = pandoc.Blocks({})
20-
-- layout
21-
for i, row in ipairs(layout.layout) do
22-
23-
local aligns = row:map(function(cell)
24-
-- get the align
25-
local align = cell.attributes[kLayoutAlign]
26-
return layoutTableAlign(align)
27-
end)
28-
local widths = row:map(function(cell)
29-
-- propagage percents if they are provided
30-
local layoutPercent = horizontalLayoutPercent(cell)
31-
if layoutPercent then
32-
return layoutPercent / 100
33-
else
34-
return 0
35-
end
36-
end)
37-
38-
local cells = pandoc.List()
39-
for _, cell in ipairs(row) do
40-
cells:insert(cell)
41-
end
42-
43-
-- make the table
44-
local panelTable = pandoc.SimpleTable(
45-
pandoc.List(), -- caption
46-
aligns,
47-
widths,
48-
pandoc.List(), -- headers
49-
{ cells }
50-
)
51-
52-
-- add it to the panel
53-
panel_content:insert(pandoc.utils.from_simple_table(panelTable))
54-
end
59+
local panel_content = make_panel_content()
5560

61+
-- outer panel to contain css and figure panel
5662
local result = pandoc.Div({})
5763
-- the format for the rawblock is html and not markdown_strict
5864
-- because this might end up inside a table, and Pandoc
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
format: hugo-md
3+
---
4+
5+
::: {layout-ncol="2"}
6+
7+
Hello.
8+
9+
Hello.
10+
11+
:::
12+

0 commit comments

Comments
 (0)