Skip to content

Commit 3b563d9

Browse files
committed
Add filters tests
1 parent 4b6f5e3 commit 3b563d9

File tree

8 files changed

+116
-0
lines changed

8 files changed

+116
-0
lines changed

tests/docs/filters/behead.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
Pandoc filter to convert all level 2+ headings to paragraphs with
5+
emphasized text.
6+
"""
7+
8+
from pandocfilters import toJSONFilter, Emph, Para
9+
10+
def behead(key, value, format, meta):
11+
if key == 'Header' and value[0] >= 2:
12+
return Para([Emph(value[2])])
13+
14+
if __name__ == "__main__":
15+
toJSONFilter(behead)

tests/docs/filters/both.qmd

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
title: Both types of filters
3+
filters:
4+
- type: json
5+
path: behead.py
6+
- type: lua
7+
path: smallcaps.lua
8+
---
9+
10+
## This should be em
11+
12+
**This should be small caps**
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
return {
3+
{
4+
Div = function (elem)
5+
if elem.attr.classes:includes("callout") then
6+
error("THERE WAS A PROCESSED CALLOUT!\nIf the filter order is correct, this should not happen.")
7+
end
8+
end,
9+
}
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: Test Filter Order
3+
filters:
4+
- fail-if-callout.lua
5+
- quarto
6+
---
7+
8+
:::{.callout-note}
9+
Note that there are five types of callouts.
10+
:::
11+

tests/docs/filters/lua-filter.qmd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: Lua Filter Test
3+
filters:
4+
- smallcaps.lua
5+
---
6+
7+
**This should be in all caps**
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
title: Test Python Filter
3+
filters:
4+
- type: json
5+
path: behead.py
6+
---
7+
8+
## This is a test
9+
10+
## This should be em

tests/docs/filters/smallcaps.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
return {
2+
{
3+
Strong = function (elem)
4+
return pandoc.SmallCaps(elem.c)
5+
end,
6+
}
7+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { ensureHtmlElements } from "../../verify.ts";
2+
import { testRender } from "../render/render.ts";
3+
import { docs, outputForInput } from "../../utils.ts";
4+
import { join } from "path/mod.ts";
5+
6+
const verifySmallCaps = ["main.content span.smallcaps"];
7+
const verifyBehead = ["main.content em"];
8+
const verifyBeheadExclude = ["h2"];
9+
10+
// Test that the small cap filter properly runs
11+
const luaInput = docs(join("filters", "lua-filter.qmd"));
12+
const luaOutput = outputForInput(luaInput, "html");
13+
testRender(luaInput, "html", false, [
14+
ensureHtmlElements(luaOutput.outputPath, [
15+
...verifySmallCaps,
16+
]),
17+
]);
18+
19+
// Test that the python behead filter is working
20+
const pythonInput = docs(join("filters", "python-filter.qmd"));
21+
const pythonOutput = outputForInput(pythonInput, "html");
22+
testRender(pythonInput, "html", false, [
23+
ensureHtmlElements(pythonOutput.outputPath, [
24+
...verifyBehead,
25+
], [
26+
...verifyBeheadExclude,
27+
]),
28+
]);
29+
30+
// Test that the python behead filter is working
31+
const bothInput = docs(join("filters", "both.qmd"));
32+
const bothOutput = outputForInput(bothInput, "html");
33+
testRender(bothInput, "html", false, [
34+
ensureHtmlElements(bothOutput.outputPath, [
35+
...verifySmallCaps,
36+
...verifyBehead,
37+
], [
38+
...verifyBeheadExclude,
39+
]),
40+
]);
41+
42+
// Test that filter order works
43+
const orderInput = docs(join("filters", "filter-order.qmd"));
44+
testRender(orderInput, "html", false);

0 commit comments

Comments
 (0)