Lua Utils module: improve stringify

Meta value strings (MetaString) and booleans (MetaBool) are now
converted to the literal string and the lowercase boolean name,
respectively. Previously, all values of these types were converted to
the empty string.
This commit is contained in:
Albert Krewinkel 2018-11-17 16:50:33 +01:00
parent f07ae68558
commit 1b15913b6e
No known key found for this signature in database
GPG key ID: 388DC0B21F631124

View file

@ -32,10 +32,11 @@ module Text.Pandoc.Lua.Module.Utils
import Prelude
import Control.Applicative ((<|>))
import Data.Char (toLower)
import Data.Default (def)
import Foreign.Lua (Peekable, Lua, NumResults)
import Text.Pandoc.Class (runIO, setUserDataDir)
import Text.Pandoc.Definition (Pandoc, Meta, MetaValue, Block, Inline)
import Text.Pandoc.Definition (Pandoc, Meta, MetaValue (..), Block, Inline)
import Text.Pandoc.Lua.StackInstances ()
import Text.Pandoc.Lua.Util (addFunction)
@ -111,7 +112,13 @@ stringify el = return $ case el of
InlineElement i -> Shared.stringify i
BlockElement b -> Shared.stringify b
MetaElement m -> Shared.stringify m
MetaValueElement m -> Shared.stringify m
MetaValueElement m -> stringifyMetaValue m
stringifyMetaValue :: MetaValue -> String
stringifyMetaValue mv = case mv of
MetaBool b -> map toLower (show b)
MetaString s -> s
_ -> Shared.stringify mv
data AstElement
= PandocElement Pandoc