Lua filters: Remove special treatment of Quoted, Math.

No more SingleQuoted, DoubleQuoted, InlineMath, DisplayMath.
This makes everything uniform and predictable, though it does
open up a difference btw lua filters and custom writers.
This commit is contained in:
John MacFarlane 2017-06-29 15:47:27 +02:00
parent 5c80aca0e2
commit 780a65f8a8
2 changed files with 12 additions and 26 deletions

View file

@ -101,6 +101,12 @@ data LuaFilter = LuaFilter LuaState FunctionMap
newtype LuaFilterFunction = LuaFilterFunction { functionIndex :: Int }
tryFilter :: StackValue a => LuaState -> FunctionMap -> String -> a -> IO a
tryFilter lua fnMap filterFnName x =
case Map.lookup filterFnName fnMap of
Nothing -> return x
Just fn -> runFilterFunction lua fn x
execDocLuaFilter :: LuaState
-> FunctionMap
-> Pandoc -> IO Pandoc
@ -116,34 +122,12 @@ execMetaLuaFilter lua fnMap (Pandoc meta blks) = do
execBlockLuaFilter :: LuaState
-> FunctionMap
-> Block -> IO Block
execBlockLuaFilter lua fnMap x = do
tryFilter lua fnMap (show (toConstr x)) x
tryFilter :: StackValue a => LuaState -> FunctionMap -> String -> a -> IO a
tryFilter lua fnMap filterFnName x =
case Map.lookup filterFnName fnMap of
Nothing -> return x
Just fn -> runFilterFunction lua fn x
tryFilterAlternatives :: StackValue a
=> LuaState -> FunctionMap -> [String] -> a -> IO a
tryFilterAlternatives _ _ [] x = return x
tryFilterAlternatives lua fnMap (fnName : alternatives) x =
case Map.lookup fnName fnMap of
Nothing -> tryFilterAlternatives lua fnMap alternatives x
Just fn -> runFilterFunction lua fn x
execBlockLuaFilter lua fnMap x = tryFilter lua fnMap (show (toConstr x)) x
execInlineLuaFilter :: LuaState
-> FunctionMap
-> Inline -> IO Inline
execInlineLuaFilter lua fnMap x = do
let tryAlt = tryFilterAlternatives lua fnMap
case x of
Math DisplayMath _ -> tryAlt ["DisplayMath", "Math"] x
Math InlineMath _ -> tryAlt ["InlineMath", "Math"] x
Quoted DoubleQuote _ -> tryAlt ["DoubleQuoted", "Quoted"] x
Quoted SingleQuote _ -> tryAlt ["SingleQuoted", "Quoted"] x
_ -> tryFilter lua fnMap (show (toConstr x)) x
execInlineLuaFilter lua fnMap x = tryFilter lua fnMap (show (toConstr x)) x
instance StackValue LuaFilter where
valuetype _ = Lua.TTABLE

View file

@ -1,7 +1,9 @@
return {
{
SingleQuoted = function (elem)
elem.quotetype = "DoubleQuote"
Quoted = function (elem)
if elem.quotetype == "SingleQuote" then
elem.quotetype = "DoubleQuote"
end
return elem
end,
}