aboutsummaryrefslogtreecommitdiff
path: root/test/Tests
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2020-01-15 23:26:00 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2020-01-15 14:26:00 -0800
commit672a4bdd1d4a587feaa38613fce64335adaad76d (patch)
tree17e58c93a24eedba8fc06aa28f661395e1057096 /test/Tests
parent400b29d10e9ba20479692ff2e2a482bb27bfe09f (diff)
downloadpandoc-672a4bdd1d4a587feaa38613fce64335adaad76d.tar.gz
Lua filters: allow filtering of element lists (#6040)
Lists of Inline and Block elements can now be filtered via `Inlines` and `Blocks` functions, respectively. This is helpful if a filter conversion depends on the order of elements rather than a single element. For example, the following filter can be used to remove all spaces before a citation: function isSpaceBeforeCite (spc, cite) return spc and spc.t == 'Space' and cite and cite.t == 'Cite' end function Inlines (inlines) for i = #inlines-1,1,-1 do if isSpaceBeforeCite(inlines[i], inlines[i+1]) then inlines:remove(i) end end return inlines end Closes: #6038
Diffstat (limited to 'test/Tests')
-rw-r--r--test/Tests/Lua.hs25
1 files changed, 24 insertions, 1 deletions
diff --git a/test/Tests/Lua.hs b/test/Tests/Lua.hs
index 7683df09f..5e01266c0 100644
--- a/test/Tests/Lua.hs
+++ b/test/Tests/Lua.hs
@@ -23,7 +23,8 @@ import Text.Pandoc.Arbitrary ()
import Text.Pandoc.Builder (bulletList, definitionList, displayMath, divWith,
doc, doubleQuoted, emph, header, lineBlock,
linebreak, math, orderedList, para, plain, rawBlock,
- singleQuoted, space, str, strong)
+ singleQuoted, space, str, strong,
+ HasMeta (setMeta))
import Text.Pandoc.Class (runIOorExplode, setUserDataDir)
import Text.Pandoc.Definition (Block (BlockQuote, Div, Para), Inline (Emph, Str),
Attr, Meta, Pandoc, pandocTypesVersion)
@@ -129,6 +130,28 @@ tests = map (localOption (QuickCheckTests 20))
(doc $ divWith ("", [], kv_before) (para "nil"))
(doc $ divWith ("", [], kv_after) (para "nil"))
+ , testCase "Filter list of inlines" $
+ assertFilterConversion "List of inlines"
+ "inlines-filter.lua"
+ (doc $ para ("Hello," <> linebreak <> "World! Wassup?"))
+ (doc $ para "Hello, World! Wassup?")
+
+ , testCase "Filter list of blocks" $
+ assertFilterConversion "List of blocks"
+ "blocks-filter.lua"
+ (doc $ para "one." <> para "two." <> para "three.")
+ (doc $ plain "3")
+
+ , testCase "Filter Meta" $
+ let setMetaBefore = setMeta "old" ("old" :: T.Text)
+ . setMeta "bool" False
+ setMetaAfter = setMeta "new" ("new" :: T.Text)
+ . setMeta "bool" True
+ in assertFilterConversion "Meta filtering"
+ "meta.lua"
+ (setMetaBefore . doc $ mempty)
+ (setMetaAfter . doc $ mempty)
+
, testCase "Script filename is set" $
assertFilterConversion "unexpected script name"
"script-name.lua"