-
Notifications
You must be signed in to change notification settings - Fork 0
/
pandoc-filter.js
executable file
·52 lines (40 loc) · 1.21 KB
/
pandoc-filter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env node
'use strict';
const pandoc = require('pandoc-filter');
const {RawInline, Image} = pandoc;
function customReplace(type, value, format, meta) {
if (format === 'plain' && type === 'Emph') {
// remove emphasize for txt output
return value;
}
if (format !== 'latex') {
return;
}
if (type === 'Str') {
return stringReplace(value);
}
// link to PDF images instead of SVG ones
if (type === 'Image') {
const [attrs, alt, [src, title]] = value;
return Image(attrs, alt, [src.replace('.svg', '.pdf'), title]);
}
}
function stringReplace(value) {
let changed = false;
// replace :x: and :ok: with their corresponding, colored unicode symbols
if (value.match(/:x:|:ok:|:oksw:/)) {
value = value.replace(/:x:/g, '\\textcolor{FireBrick}{\\ding{55}}');
value = value.replace(/:ok:/g, '\\textcolor{ForestGreen}{\\ding{51}}');
value = value.replace(/:oksw:/g, '\\ding{51}');
changed = true;
}
// replace ↩ with latex newline (especially useful in multiline tables)
if (value.includes('↩')) {
value = value.replace('↩', '\\\\\n');
changed = true;
}
if (changed) {
return RawInline('latex', value);
}
}
pandoc.stdio(customReplace);