From 9f984ff26ac248a27212a37ab34754a2e9261e8c Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 7 Sep 2019 11:23:12 -0700 Subject: Replace Element and makeHierarchical with makeSections. Text.Pandoc.Shared: + Remove `Element` type [API change] + Remove `makeHierarchicalize` [API change] + Add `makeSections` [API change] + Export `deLink` [API change] Now that we have Divs, we can use them to represent the structure of sections, and we don't need a special Element type. `makeSections` reorganizes a block list, adding Divs with class `section` around sections, and adding numbering if needed. This change also fixes some longstanding issues recognizing section structure when the document contains Divs. Closes #3057, see also #997. All writers have been changed to use `makeSections`. Note that in the process we have reverted the change c1d058aeb1c6a331a2cc22786ffaab17f7118ccd made in response to #5168, which I'm not completely sure was a good idea. Lua modules have also been adjusted accordingly. Existing lua filters that use `hierarchicalize` will need to be rewritten to use `make_sections`. --- src/Text/Pandoc/Lua/Marshaling/AST.hs | 31 ------------------------------- 1 file changed, 31 deletions(-) (limited to 'src/Text/Pandoc/Lua/Marshaling') diff --git a/src/Text/Pandoc/Lua/Marshaling/AST.hs b/src/Text/Pandoc/Lua/Marshaling/AST.hs index 7b428b5f0..c9d61d3e4 100644 --- a/src/Text/Pandoc/Lua/Marshaling/AST.hs +++ b/src/Text/Pandoc/Lua/Marshaling/AST.hs @@ -22,12 +22,9 @@ module Text.Pandoc.Lua.Marshaling.AST import Prelude import Control.Applicative ((<|>)) import Foreign.Lua (Lua, Peekable, Pushable, StackIndex) -import Foreign.Lua.Userdata ( ensureUserdataMetatable, pushAnyWithMetatable - , metatableName) import Text.Pandoc.Definition import Text.Pandoc.Lua.Util (defineHowTo, pushViaConstructor) import Text.Pandoc.Lua.Marshaling.CommonState () -import Text.Pandoc.Shared (Element (Blk, Sec)) import qualified Foreign.Lua as Lua import qualified Text.Pandoc.Lua.Util as LuaUtil @@ -285,31 +282,3 @@ instance Pushable LuaListAttributes where instance Peekable LuaListAttributes where peek = defineHowTo "get ListAttributes value" . fmap LuaListAttributes . Lua.peek - --- --- Hierarchical elements --- -instance Pushable Element where - push (Blk blk) = Lua.push blk - push sec = pushAnyWithMetatable pushElementMetatable sec - where - pushElementMetatable = ensureUserdataMetatable (metatableName sec) $ - LuaUtil.addFunction "__index" indexElement - -instance Peekable Element where - peek idx = Lua.ltype idx >>= \case - Lua.TypeUserdata -> Lua.peekAny idx - _ -> Blk <$> Lua.peek idx - -indexElement :: Element -> String -> Lua Lua.NumResults -indexElement = \case - (Blk _) -> const (1 <$ Lua.pushnil) -- this shouldn't happen - (Sec lvl num attr label contents) -> fmap (return 1) . \case - "level" -> Lua.push lvl - "numbering" -> Lua.push num - "attr" -> Lua.push (LuaAttr attr) - "label" -> Lua.push label - "contents" -> Lua.push contents - "tag" -> Lua.push "Sec" - "t" -> Lua.push "Sec" - _ -> Lua.pushnil -- cgit v1.2.3