git.iko.soy/typeable/pandoc
on master help sign in
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.

commit780a65f8a87b40d1a9ee269cd7a51699c42d497e authorJohn MacFarlane <jgm@berkeley.edu> dateThu 29 Jun 2017, 15:47 (9 years ago) parent5c80aca
2 files changed+12−26
src/Text/Pandoc/Lua.hs+8−24 test/lua/single-to-double-quoted.lua+4−2
src/Text/Pandoc/Lua.hs+8−24
@@ -101,6 +101,12 @@ data LuaFilter = LuaFilter LuaState FunctionMap
101101
102102newtype LuaFilterFunction = LuaFilterFunction { functionIndex :: Int }
103103
104+tryFilter :: StackValue a => LuaState -> FunctionMap -> String -> a -> IO a
105+tryFilter lua fnMap filterFnName x =
106+ case Map.lookup filterFnName fnMap of
107+ Nothing -> return x
108+ Just fn -> runFilterFunction lua fn x
109+
104110execDocLuaFilter :: LuaState
105111 -> FunctionMap
106112 -> Pandoc -> IO Pandoc
@@ -116,34 +122,12 @@ execMetaLuaFilter lua fnMap (Pandoc meta blks) = do
116122execBlockLuaFilter :: LuaState
117123 -> FunctionMap
118124 -> Block -> IO Block
119−execBlockLuaFilter lua fnMap x = do
120− tryFilter lua fnMap (show (toConstr x)) x
121−
122−tryFilter :: StackValue a => LuaState -> FunctionMap -> String -> a -> IO a
123−tryFilter lua fnMap filterFnName x =
124− case Map.lookup filterFnName fnMap of
125− Nothing -> return x
126− Just fn -> runFilterFunction lua fn x
127−
128−tryFilterAlternatives :: StackValue a
129− => LuaState -> FunctionMap -> [String] -> a -> IO a
130−tryFilterAlternatives _ _ [] x = return x
131−tryFilterAlternatives lua fnMap (fnName : alternatives) x =
132− case Map.lookup fnName fnMap of
133− Nothing -> tryFilterAlternatives lua fnMap alternatives x
134− Just fn -> runFilterFunction lua fn x
125+execBlockLuaFilter lua fnMap x = tryFilter lua fnMap (show (toConstr x)) x
135126
136127execInlineLuaFilter :: LuaState
137128 -> FunctionMap
138129 -> Inline -> IO Inline
139−execInlineLuaFilter lua fnMap x = do
140− let tryAlt = tryFilterAlternatives lua fnMap
141− case x of
142− Math DisplayMath _ -> tryAlt ["DisplayMath", "Math"] x
143− Math InlineMath _ -> tryAlt ["InlineMath", "Math"] x
144− Quoted DoubleQuote _ -> tryAlt ["DoubleQuoted", "Quoted"] x
145− Quoted SingleQuote _ -> tryAlt ["SingleQuoted", "Quoted"] x
146− _ -> tryFilter lua fnMap (show (toConstr x)) x
130+execInlineLuaFilter lua fnMap x = tryFilter lua fnMap (show (toConstr x)) x
147131
148132instance StackValue LuaFilter where
149133 valuetype _ = Lua.TTABLE
test/lua/single-to-double-quoted.lua+4−2
@@ -1,7 +1,9 @@
11return {
22 {
3− SingleQuoted = function (elem)
4− elem.quotetype = "DoubleQuote"
3+ Quoted = function (elem)
4+ if elem.quotetype == "SingleQuote" then
5+ elem.quotetype = "DoubleQuote"
6+ end
57 return elem
68 end,
79 }