Skip to content

Commit

Permalink
try to fix bug in some configs
Browse files Browse the repository at this point in the history
Usually Pandoc returns the key 'pandoc-api-version' first:

```
>>> echo "a" | pandoc --to=json

{"pandoc-api-version":[1,17,0,4],"meta":{},"blocks":[{"t":"Para","c":[{"t":"Str","c":"\"a\""}]}]}
```

But this is not the case in some systems (which ones?):

```
cat pftest.md | pandoc -t json
{"blocks":[{"t":"Para","c":[{"t":"Str","c":"From"}... ,
],"pandoc-api-version":[1,17,0,4],"meta":{"author":{ ....
```

This workaround should fix that problem, but if the key order is
different at other places that might create future issues.
  • Loading branch information
sergiocorreia committed Nov 3, 2016
1 parent ec71b72 commit 2686e76
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions panflute/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -1338,13 +1338,16 @@ def from_json(data):
return c

# Document (New API)
if data[0][0] == 'pandoc-api-version':
assert len(data) == 3
assert data[1][0] == 'meta'
assert data[2][0] == 'blocks'
api, meta, items = (pair[1] for pair in data)
doc = Doc(*items, api_version=api, metadata=meta)
return doc
if len(data) == 3:
# It seems that (in some configs or systems),
# the first element might not always be "pandoc-api-version"
if data[0][0] in ('pandoc-api-version', 'meta', 'blocks'):
data = OrderedDict(data)
api = data['pandoc-api-version']
meta = data['meta']
items = data['blocks']

return Doc(*items, api_version=api, metadata=meta)

# Metadata contents
if data[0][0] != 't':
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,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='1.4.0',
version='1.4.1',

description='Pythonic Pandoc filters',
long_description=long_description,
Expand Down

0 comments on commit 2686e76

Please sign in to comment.