Skip to content

Commit

Permalink
feat: (Djot extension) caption on Div blocks
Browse files Browse the repository at this point in the history
We already added caption support on block quotes earlier.
This adds it too for divs, interpreted as captioned figures.
  • Loading branch information
Omikhleia authored and Didier Willis committed Feb 12, 2024
1 parent 0c247c9 commit 00ae975
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions inputters/djot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ function Renderer:blockquote (node)
local pos = node_pos(node)
local out
if node.caption then
-- Djot extension: caption supported on blockquotes
local caption = self:render_children(node.caption)
out = createStructuredCommand("markdown:internal:captioned-blockquote", node.attr or {}, {
content,
Expand All @@ -210,7 +211,18 @@ end
function Renderer:div (node)
local options = node.attr or {}
local content = self:render_children(node)
return createCommand("markdown:internal:div", options, content, node_pos(node))
local pos = node_pos(node)
local out
--- Djot extension: caption supported on div blocks
out = createCommand("markdown:internal:div", options, content, pos)
if node.caption then
local caption = self:render_children(node.caption)
out = createStructuredCommand("markdown:internal:captioned-figure", node.attr or {}, {
out,
createCommand("caption", {}, caption)
}, pos)
end
return out
end

function Renderer:section (node)
Expand Down Expand Up @@ -257,7 +269,15 @@ function Renderer:code_block (node)
end
end
end
return createCommand("markdown:internal:codeblock", options, node.s, node_pos(node))
local pos = node_pos(node)
local out
out = createCommand("markdown:internal:codeblock", options, node.s, pos)
if node.caption then
-- Potential Djot extension (but not yet -- explicit wrapping in a div block might
-- be sufficient for now.
SU.warn("Caption on code block is not supported (ignored)")
end
return out
end

function Renderer:table (node)
Expand Down

0 comments on commit 00ae975

Please sign in to comment.