Skip to content

Commit

Permalink
Merge pull request #9 from quarto-lab/cr-sidebar-shift-class-to-block
Browse files Browse the repository at this point in the history
Cr sidebar shift class to block
  • Loading branch information
andrewpbray authored Aug 2, 2023
2 parents 53b3ef5 + a9f811b commit 54dcc66
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
37 changes: 24 additions & 13 deletions _extensions/cr-sidebar/cr-sidebar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ function make_sidebar_layout(div)
sticky_blocks = div.content:walk {
traverse = 'topdown',
Block = function(block)
quarto.log.output(">>>>> is sticky: ", is_sticky(block))
quarto.log.output(">>>>> block: ", block)
if is_sticky(block) then
block = shift_class_to_block(block)
return block, false -- if a sticky element is found, don't process child blocks
else
return {}
Expand All @@ -29,33 +28,45 @@ function make_sidebar_layout(div)
end
}

quarto.log.output("<><><> Sticky Blocks <><><>")
quarto.log.output(sticky_blocks)
quarto.log.output("<><><> Non Sticky Blocks <><><>")
quarto.log.output(non_sticky_blocks)

sidebar_col = pandoc.Div(non_sticky_blocks,
narrative_col = pandoc.Div(non_sticky_blocks,
pandoc.Attr("", {"column", "sidebar_col"}, {width = "30%"}))
body_col_stack = pandoc.Div(sticky_blocks,
sticky_col_stack = pandoc.Div(sticky_blocks,
pandoc.Attr("", {"body_col_stack"}))
body_col = pandoc.Div(body_col_stack,
sticky_col = pandoc.Div(sticky_col_stack,
pandoc.Attr("", {"column", "body_col"}, {width = "55%"}))
layout = pandoc.Div({sidebar_col, body_col},
layout = pandoc.Div({narrative_col, sticky_col},
pandoc.Attr("", {"columns", "column-page", table.unpack(div.classes)},
{}))

return layout
end
end

function shift_class_to_block(block)

if pandoc.utils.type(block.content) == "Inlines" then
for _, inline in pairs(block.content) do
if inline.attr ~= nil then
if inline.classes:includes("cr-sticky") then
-- wraps block in Div with class cr-sticky (and converts Para to Plain)
block = pandoc.Div(block.content, pandoc.Attr("", {"cr-sticky"}, {}))
end
end
end
end

return block
end


function is_sticky(block)

sticky_block_class = false
sticky_block_attribute = false
sticky_inline_class = false

if block.attr ~= nil then
sticky_block_class = block.attr.classes:includes("cr-sticky")
sticky_block_class = block.classes:includes("cr-sticky")
end

if block.attributes ~= nil then
Expand All @@ -70,7 +81,7 @@ function is_sticky(block)
if pandoc.utils.type(block.content) == "Inlines" then
for _, inline in pairs(block.content) do
if inline.attr ~= nil then
sticky_inline_class = inline.attr.classes:includes("cr-sticky")
sticky_inline_class = inline.classes:includes("cr-sticky")
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions sidebar-cr-multiple-block-types.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,17 @@ flowchart LR
C --> E[Result two]
```

:::

This is a graphviz diagram

```{dot}
//| cr: sticky
graph G {
layout=neato
run -- intr;
intr -- runbl;
}
```

:::

# The End

0 comments on commit 54dcc66

Please # to comment.