diff --git a/_extensions/cr-sidebar/cr-sidebar.lua b/_extensions/cr-sidebar/cr-sidebar.lua index b75e4bc..635bda3 100644 --- a/_extensions/cr-sidebar/cr-sidebar.lua +++ b/_extensions/cr-sidebar/cr-sidebar.lua @@ -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 {} @@ -29,18 +28,13 @@ 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)}, {})) @@ -48,6 +42,23 @@ function make_sidebar_layout(div) 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 @@ -55,7 +66,7 @@ function is_sticky(block) 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 @@ -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 diff --git a/sidebar-cr-multiple-block-types.qmd b/sidebar-cr-multiple-block-types.qmd index 31ea082..5ad9bb2 100644 --- a/sidebar-cr-multiple-block-types.qmd +++ b/sidebar-cr-multiple-block-types.qmd @@ -85,11 +85,10 @@ flowchart LR C --> E[Result two] ``` -::: - This is a graphviz diagram ```{dot} +//| cr: sticky graph G { layout=neato run -- intr; @@ -97,4 +96,6 @@ graph G { } ``` +::: + # The End \ No newline at end of file