-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscaps-simple.py
executable file
·41 lines (33 loc) · 1.29 KB
/
scaps-simple.py
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
#!/usr/bin/env python3
from pandocfilters import walk, toJSONFilter, RawInline, Str
import regex # allow unicode character properties
"""prepare smallcaps for macro that needs upper case letters."""
def upstr(key, value, fmt, _meta):
"""replace lower-case letters by macro-wrapped upper-case letters"""
if fmt == "ms":
if key == 'Str':
words = regex.finditer(
r'(?P<U>\p{Lu}*)(?P<L>\p{Ll}*)(?P<R>[^\p{Ll}\p{Lu}]*)',
value)
if words:
ret = [RawInline("ms", "\n")]
for w in words:
if w[2]: # not useful if nothing will be small-capped
cmd = f'.SCAP "{w[1]}" "{w[2].upper()}"'
if w[3]:
cmd += ' "{w[3]}"'
cmd += '\n'
ret.append(
RawInline(
"ms",
cmd))
else:
ret.append(Str(w[0]))
return ret
return None # else change nothing
def scaps(key, val, fmt, meta):
if fmt == "ms":
if key == 'SmallCaps':
return walk(val, upstr, fmt, meta)
if __name__ == "__main__":
toJSONFilter(scaps)