Skip to content

Commit 9cab84a

Browse files
committed
Handle Figures in Lua
1 parent ea87a27 commit 9cab84a

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

data/pandoc.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,22 @@ M.Div = M.Block:create_constructor(
469469
{{attr = {"identifier", "classes", "attributes"}}, "content"}
470470
)
471471

472+
473+
--- Creates a figure element.
474+
-- @function Figure
475+
-- @tparam {Block,...} content figure block contents
476+
-- @tparam Caption caption figure caption
477+
-- @tparam[opt] Attr attr element attributes
478+
-- @treturn Block figure element
479+
M.Figure = M.Block:create_constructor(
480+
"Figure",
481+
function(content, caption, attr)
482+
return {c = {ensureAttr(attr), caption, ensureList(content)}}
483+
end,
484+
{{attr = {"identifier", "classes", "attributes"}}, "caption", "content"}
485+
)
486+
487+
472488
--- Creates a header element.
473489
-- @function Header
474490
-- @tparam int level header level

src/Text/Pandoc/Lua/Marshaling/AST.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ pushBlock = \case
160160
CodeBlock attr code -> pushViaConstructor "CodeBlock" code (LuaAttr attr)
161161
DefinitionList items -> pushViaConstructor "DefinitionList" items
162162
Div attr blcks -> pushViaConstructor "Div" blcks (LuaAttr attr)
163+
Figure attr capt blcks -> pushViaConstructor "Figure" blcks capt (LuaAttr attr)
163164
Header lvl attr inlns -> pushViaConstructor "Header" lvl inlns (LuaAttr attr)
164165
HorizontalRule -> pushViaConstructor "HorizontalRule"
165166
LineBlock blcks -> pushViaConstructor "LineBlock" blcks
@@ -171,7 +172,6 @@ pushBlock = \case
171172
RawBlock f cs -> pushViaConstructor "RawBlock" f cs
172173
Table attr blkCapt specs thead tbody tfoot ->
173174
pushViaConstructor "Table" blkCapt specs thead tbody tfoot attr
174-
Figure {} -> undefined -- pushViaConstructor "Figure" capt body attr
175175

176176
-- | Return the value at the given index as block if possible.
177177
peekBlock :: StackIndex -> Lua Block
@@ -183,6 +183,8 @@ peekBlock idx = defineHowTo "get Block value" $! do
183183
"CodeBlock" -> withAttr CodeBlock <$!> elementContent
184184
"DefinitionList" -> DefinitionList <$!> elementContent
185185
"Div" -> withAttr Div <$!> elementContent
186+
"Figure" -> (\(LuaAttr attr, capt, bs) -> Figure attr capt bs)
187+
<$!> elementContent
186188
"Header" -> (\(lvl, LuaAttr attr, lst) -> Header lvl attr lst)
187189
<$!> elementContent
188190
"HorizontalRule" -> return HorizontalRule

0 commit comments

Comments
 (0)