Skip to content

Commit

Permalink
enclose tabsets next to sidebars in fill panel
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed Oct 12, 2023
1 parent e8886b6 commit ce93c90
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/resources/filters/ast/customnodes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ function scaffold(node)
end
end

function is_custom_node(node)
function is_custom_node(node, name)
if node.attributes and node.attributes.__quarto_custom == "true" then
return node
if name == nil or name == node.attributes.__quarto_custom_type then
return node
end
end
return false
end
Expand Down
10 changes: 9 additions & 1 deletion src/resources/filters/quarto-pre/panel-sidebar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ function bootstrap_panel_sidebar()
local function isSidebar(el)
return el ~= nil and el.t == "Div" and el.attr.classes:includes("panel-sidebar")
end
local function isTabset(el) return is_custom_node(el, "Tabset") end
local function fillPanel(el) return pandoc.Div({ el }, pandoc.Attr("", {"panel-fill"})) end
local function isContainer(el)
return el ~= nil and
el.t == "Div" and
(el.attr.classes:includes("panel-fill") or
el.attr.classes:includes("panel-center") or
el.attr.classes:includes("panel-tabset"))
isTabset(el))
end
local function isHeader(el)
return el ~= nil and el.t == "Header"
Expand Down Expand Up @@ -59,13 +61,19 @@ function bootstrap_panel_sidebar()
if isContainer(blocks[sidebarIdx - 1]) then
blocks:remove(sidebarIdx)
local container = blocks:remove(sidebarIdx - 1)
if isTabset(container) then
container = fillPanel(container)
end
transferAttr(containerAttr, container.attr)
blocks:insert(sidebarIdx - 1,
pandoc.Div({ container, sidebar }, sidebarHandler.rowAttr({"layout-sidebar-right"}))
)
-- sidebar before container
elseif isContainer(blocks[sidebarIdx + 1]) then
local container = blocks:remove(sidebarIdx + 1)
if isTabset(container) then
container = fillPanel(container)
end
transferAttr(containerAttr, container.attr)
blocks:remove(sidebarIdx)
blocks:insert(sidebarIdx,
Expand Down

0 comments on commit ce93c90

Please sign in to comment.