-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlinkref.py
33 lines (27 loc) · 935 Bytes
/
linkref.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
#!/usr/bin/env python
"""
Pandoc filter to convert links starting with "#" to \autoref calls.
"""
# debugging
from __future__ import print_function
import sys
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
from pandocfilters import toJSONFilter, RawInline, Str
def latex(x):
return RawInline('latex', x)
def linkref(key, value, format, meta):
#eprint("Key: " + key)
if key == 'Link':
#eprint(value)
url = value[2][0]
if len(url) > 1 and url[0] == '#':
labels = url[1:].split(";%20#")
if format == "latex":
return (latex('\\autoref{' + ",".join(labels) + '}'))
elif format == "html" or format == "html5":
# If no title given, set title to reference label
if value[1] == []:
value[1] = [Str (", ".join(labels))]
if __name__ == "__main__":
toJSONFilter(linkref)