git.iko.soy/typeable/pandoc
on master help sign in
Lua filters: push ListAttributes via constructor

This ensures that ListAttributes, as present in OrderedList elements, have additional accessors (viz. *start*, *style*, and *delimiter*).

commit3db9e15689766b7f416e0410252297dff11bd770 authorAlbert Krewinkel <albert@zeitkraut.de> dateFri 12 Oct 2018, 21:13 (8 years ago) parent1ac87b4
2 files changed+17−2
src/Text/Pandoc/Lua/Init.hs+1 src/Text/Pandoc/Lua/StackInstances.hs+16−2
src/Text/Pandoc/Lua/Init.hs+1
@@ -111,6 +111,7 @@ putConstructorsInRegistry = do
111111 constrsToReg $ Pandoc.MetaList mempty
112112 constrsToReg $ Pandoc.Citation mempty mempty mempty Pandoc.AuthorInText 0 0
113113 putInReg "Attr" -- used for Attr type alias
114+ putInReg "ListAttributes" -- used for ListAttributes type alias
114115 Lua.pop 1
115116 where
116117 constrsToReg :: Data a => a -> Lua ()
src/Text/Pandoc/Lua/StackInstances.hs+16−2
@@ -185,7 +185,8 @@ pushBlock = \case
185185 Header lvl attr inlns -> pushViaConstructor "Header" lvl inlns (LuaAttr attr)
186186 HorizontalRule -> pushViaConstructor "HorizontalRule"
187187 LineBlock blcks -> pushViaConstructor "LineBlock" blcks
188− OrderedList lstAttr list -> pushViaConstructor "OrderedList" list lstAttr
188+ OrderedList lstAttr list -> pushViaConstructor "OrderedList" list
189+ (LuaListAttributes lstAttr)
189190 Null -> pushViaConstructor "Null"
190191 Para blcks -> pushViaConstructor "Para" blcks
191192 Plain blcks -> pushViaConstructor "Plain" blcks
@@ -207,7 +208,9 @@ peekBlock idx = defineHowTo "get Block value" $ do
207208 <$> elementContent
208209 "HorizontalRule" -> return HorizontalRule
209210 "LineBlock" -> LineBlock <$> elementContent
210− "OrderedList" -> uncurry OrderedList <$> elementContent
211+ "OrderedList" -> (\(LuaListAttributes lstAttr, lst) ->
212+ OrderedList lstAttr lst)
213+ <$> elementContent
211214 "Null" -> return Null
212215 "Para" -> Para <$> elementContent
213216 "Plain" -> Plain <$> elementContent
@@ -289,6 +292,17 @@ instance Pushable LuaAttr where
289292instance Peekable LuaAttr where
290293 peek idx = defineHowTo "get Attr value" (LuaAttr <$> Lua.peek idx)
291294
295+-- | Wrapper for ListAttributes
296+newtype LuaListAttributes = LuaListAttributes ListAttributes
297+
298+instance Pushable LuaListAttributes where
299+ push (LuaListAttributes (start, style, delimiter)) =
300+ pushViaConstructor "ListAttributes" start style delimiter
301+
302+instance Peekable LuaListAttributes where
303+ peek = defineHowTo "get ListAttributes value" .
304+ fmap LuaListAttributes . Lua.peek
305+
292306--
293307-- Hierarchical elements
294308--