boisgera / pandoc

Pandoc (Python Library)

Home Page:https://boisgera.github.io/pandoc/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: string indices must be integers with pandoc 2.10.1

matthewlloyd opened this issue · comments

I'm hitting an incompatibility between this library and pandoc 2.10.1 when parsing a simple table with a single row and cell, see the error below.

$ pandoc --version
pandoc 2.10.1
Compiled with pandoc-types 1.21, texmath 0.12.0.2, skylighting 0.8.5
Copyright (C) 2006-2020 John MacFarlane
Web:  https://pandoc.org
This is free software; see the source for copying conditions.
There is no warranty, not even for merchantability or fitness
for a particular purpose.

$ python3
Python 3.8.2 (default, Jul 16 2020, 14:00:26)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandoc
>>> pandoc.read('<table><tr><td></td></tr></table>', format='html')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/.local/lib/python3.8/site-packages/pandoc/__init__.py", line 311, in read
    return read_json_v2(json_)
  File "/home/.local/lib/python3.8/site-packages/pandoc/__init__.py", line 634, in read_json_v2
    blocks = read_json_v2(json_["blocks"], ["list", ["Block"]])
  File "/home/.local/lib/python3.8/site-packages/pandoc/__init__.py", line 588, in read_json_v2
    return [read_json_v2(item, item_type) for item in json_]
  File "/home/.local/lib/python3.8/site-packages/pandoc/__init__.py", line 588, in <listcomp>
    return [read_json_v2(item, item_type) for item in json_]
  File "/home/.local/lib/python3.8/site-packages/pandoc/__init__.py", line 663, in read_json_v2
    args = [read_json_v2(jarg, t) for jarg, t in zip(json_args, constructor[1][1])]
  File "/home/.local/lib/python3.8/site-packages/pandoc/__init__.py", line 663, in <listcomp>
    args = [read_json_v2(jarg, t) for jarg, t in zip(json_args, constructor[1][1])]
  File "/home/.local/lib/python3.8/site-packages/pandoc/__init__.py", line 663, in read_json_v2
    args = [read_json_v2(jarg, t) for jarg, t in zip(json_args, constructor[1][1])]
  File "/home/.local/lib/python3.8/site-packages/pandoc/__init__.py", line 663, in <listcomp>
    args = [read_json_v2(jarg, t) for jarg, t in zip(json_args, constructor[1][1])]
  File "/home/.local/lib/python3.8/site-packages/pandoc/__init__.py", line 608, in read_json_v2
    return read_json_v2(json_, value_type)
  File "/home/.local/lib/python3.8/site-packages/pandoc/__init__.py", line 585, in read_json_v2
    return read_json_v2(json_, type_)
  File "/home/.local/lib/python3.8/site-packages/pandoc/__init__.py", line 588, in read_json_v2
    return [read_json_v2(item, item_type) for item in json_]
  File "/home/.local/lib/python3.8/site-packages/pandoc/__init__.py", line 588, in <listcomp>
    return [read_json_v2(item, item_type) for item in json_]
  File "/home/.local/lib/python3.8/site-packages/pandoc/__init__.py", line 619, in read_json_v2
    constructor = getattr(types, json_["t"])._def
TypeError: string indices must be integers

Yes, you're right, sorry for this. At this stage I do not properly support the recent versions of pandoc (and pandoc-types).

The why : the json serialization of the recents versions of pandoc (the original Haskell program) are not as consistent at the moment as they used to be. So at this stage I cannot (automatically, from the info available in the pandoc types hierarchy) correctly read or write json data for pandoc.

I have reported this issue upstream jgm/pandoc-types#75 and I hope that it will be sorted out. In the meantime, I should get the unsupported versions out of the supported list, so that at least you have a decent (and early) error message.

Thanks for the issue !

@matthewlloyd

I have rollbacked support for pandoc 2.10.x for the moment. If you try again, you should get:

>>> import pandoc
>>> pandoc.read("Hello, world!")
Traceback (most recent call last):
...
ValueError: pandoc 2.10.1 is not registered

Many thanks for the information, and for the great Python package. I'll downgrade my pandoc and carry on as normal until the upstream repo sorts out the type incongruity.

The 2.10.x versions of pandoc are still not supported (for the reasons explained in jgm/pandoc-types#75), but the more recent versions (2.11.4 being the latest at the moment) should be fine. Otherwise, it's a bug !