From 3db9e15689766b7f416e0410252297dff11bd770 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Fri, 12 Oct 2018 21:13:44 +0200 Subject: Lua filters: push ListAttributes via constructor This ensures that ListAttributes, as present in OrderedList elements, have additional accessors (viz. *start*, *style*, and *delimiter*). --- src/Text/Pandoc/Lua/Init.hs | 1 + src/Text/Pandoc/Lua/StackInstances.hs | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'src/Text/Pandoc/Lua') diff --git a/src/Text/Pandoc/Lua/Init.hs b/src/Text/Pandoc/Lua/Init.hs index 35611d481..8449d736d 100644 --- a/src/Text/Pandoc/Lua/Init.hs +++ b/src/Text/Pandoc/Lua/Init.hs @@ -111,6 +111,7 @@ putConstructorsInRegistry = do constrsToReg $ Pandoc.MetaList mempty constrsToReg $ Pandoc.Citation mempty mempty mempty Pandoc.AuthorInText 0 0 putInReg "Attr" -- used for Attr type alias + putInReg "ListAttributes" -- used for ListAttributes type alias Lua.pop 1 where constrsToReg :: Data a => a -> Lua () diff --git a/src/Text/Pandoc/Lua/StackInstances.hs b/src/Text/Pandoc/Lua/StackInstances.hs index 931b8c225..8538a14ee 100644 --- a/src/Text/Pandoc/Lua/StackInstances.hs +++ b/src/Text/Pandoc/Lua/StackInstances.hs @@ -185,7 +185,8 @@ pushBlock = \case Header lvl attr inlns -> pushViaConstructor "Header" lvl inlns (LuaAttr attr) HorizontalRule -> pushViaConstructor "HorizontalRule" LineBlock blcks -> pushViaConstructor "LineBlock" blcks - OrderedList lstAttr list -> pushViaConstructor "OrderedList" list lstAttr + OrderedList lstAttr list -> pushViaConstructor "OrderedList" list + (LuaListAttributes lstAttr) Null -> pushViaConstructor "Null" Para blcks -> pushViaConstructor "Para" blcks Plain blcks -> pushViaConstructor "Plain" blcks @@ -207,7 +208,9 @@ peekBlock idx = defineHowTo "get Block value" $ do <$> elementContent "HorizontalRule" -> return HorizontalRule "LineBlock" -> LineBlock <$> elementContent - "OrderedList" -> uncurry OrderedList <$> elementContent + "OrderedList" -> (\(LuaListAttributes lstAttr, lst) -> + OrderedList lstAttr lst) + <$> elementContent "Null" -> return Null "Para" -> Para <$> elementContent "Plain" -> Plain <$> elementContent @@ -289,6 +292,17 @@ instance Pushable LuaAttr where instance Peekable LuaAttr where peek idx = defineHowTo "get Attr value" (LuaAttr <$> Lua.peek idx) +-- | Wrapper for ListAttributes +newtype LuaListAttributes = LuaListAttributes ListAttributes + +instance Pushable LuaListAttributes where + push (LuaListAttributes (start, style, delimiter)) = + pushViaConstructor "ListAttributes" start style delimiter + +instance Peekable LuaListAttributes where + peek = defineHowTo "get ListAttributes value" . + fmap LuaListAttributes . Lua.peek + -- -- Hierarchical elements -- -- cgit v1.2.3