|
4 | 4 | Pandoc filter to number all kinds of things. |
5 | 5 | """ |
6 | 6 |
|
7 | | -from pandocfilters import walk, stringify, Str, Space, Para, Strong, Span, Link, Emph, RawInline |
| 7 | +from pandocfilters import toJSONFilters, walk, stringify, Str, Space, Para, Strong, Span, Link, Emph, RawInline |
8 | 8 | from functools import reduce |
9 | 9 | import sys |
10 | 10 | import json |
|
16 | 16 | count = {} |
17 | 17 | information = {} |
18 | 18 |
|
19 | | -def toJSONFilters(actions): |
20 | | - """Converts a list of actions into a filter |
21 | | - """ |
22 | | - try: |
23 | | - input_stream = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8') |
24 | | - except AttributeError: |
25 | | - # Python 2 does not have sys.stdin.buffer. |
26 | | - # REF: http://stackoverflow.com/questions/2467928/python-unicodeencodeerror-when-reading-from-stdin |
27 | | - input_stream = codecs.getreader("utf-8")(sys.stdin) |
28 | | - |
29 | | - doc = json.loads(input_stream.read()) |
30 | | - |
31 | | - if len(sys.argv) > 1: |
32 | | - format = sys.argv[1] |
33 | | - else: |
34 | | - format = "" |
35 | | - |
36 | | - altered = reduce(lambda x, action: walk(x, action, format, doc[0]['unMeta']), actions, doc) |
37 | | - json.dump(altered, sys.stdout) |
38 | | - |
39 | 19 | def removeAccents(string): |
40 | 20 | nfkd_form = unicodedata.normalize('NFKD', string) |
41 | 21 | return u"".join([c for c in nfkd_form if not unicodedata.combining(c)]) |
@@ -122,7 +102,13 @@ def referencing(key, value, format, meta): |
122 | 102 |
|
123 | 103 | # Is it a link with a right reference? |
124 | 104 | if key == 'Link': |
125 | | - [text, [reference, title]] = value |
| 105 | + try: |
| 106 | + # pandoc 1.15 |
| 107 | + [text, [reference, title]] = value |
| 108 | + except ValueError: |
| 109 | + # pandoc 1.16 |
| 110 | + [attributes, text, [reference, title]] = value |
| 111 | + |
126 | 112 | if re.match('^#([a-zA-Z][\w:.-]*)?$', reference): |
127 | 113 | # Compute the name |
128 | 114 | tag = reference[1:] |
|
0 commit comments