Skip to content

Commit

Permalink
Updating for pandoc 1.16
Browse files Browse the repository at this point in the history
  • Loading branch information
chdemko committed Feb 5, 2016
1 parent 443308b commit 4a104b5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 24 deletions.
30 changes: 8 additions & 22 deletions pandoc_numbering.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Pandoc filter to number all kinds of things.
"""

from pandocfilters import walk, stringify, Str, Space, Para, Strong, Span, Link, Emph, RawInline
from pandocfilters import toJSONFilters, walk, stringify, Str, Space, Para, Strong, Span, Link, Emph, RawInline
from functools import reduce
import sys
import json
Expand All @@ -16,26 +16,6 @@
count = {}
information = {}

def toJSONFilters(actions):
"""Converts a list of actions into a filter
"""
try:
input_stream = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')
except AttributeError:
# Python 2 does not have sys.stdin.buffer.
# REF: http://stackoverflow.com/questions/2467928/python-unicodeencodeerror-when-reading-from-stdin
input_stream = codecs.getreader("utf-8")(sys.stdin)

doc = json.loads(input_stream.read())

if len(sys.argv) > 1:
format = sys.argv[1]
else:
format = ""

altered = reduce(lambda x, action: walk(x, action, format, doc[0]['unMeta']), actions, doc)
json.dump(altered, sys.stdout)

def removeAccents(string):
nfkd_form = unicodedata.normalize('NFKD', string)
return u"".join([c for c in nfkd_form if not unicodedata.combining(c)])
Expand Down Expand Up @@ -122,7 +102,13 @@ def referencing(key, value, format, meta):

# Is it a link with a right reference?
if key == 'Link':
[text, [reference, title]] = value
try:
# pandoc 1.15
[text, [reference, title]] = value
except ValueError:
# pandoc 1.16
[attributes, text, [reference, title]] = value

if re.match('^#([a-zA-Z][\w:.-]*)?$', reference):
# Compute the name
tag = reference[1:]
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='0.3.2',
version='0.3.3',

# The project's description
description='A pandoc filter for automatic numbering',
Expand Down Expand Up @@ -95,7 +95,7 @@
# your project is installed. For an analysis of "install_requires" vs pip's
# requirements files see:
# https://packaging.python.org/en/latest/requirements.html
install_requires=['pandocfilters'],
install_requires=['pandocfilters>=1.3'],

# List additional groups of dependencies here (e.g. development
# dependencies). You can install these using the following syntax,
Expand Down

0 comments on commit 4a104b5

Please sign in to comment.