tomduck / pandoc-xnos

Library code for pandoc-fignos/eqnos/tablenos/secnos.
GNU General Public License v3.0
106 stars 27 forks source link

pandoc-xnos fails with TypeError #16

Closed flythereddflagg closed 4 years ago

flythereddflagg commented 4 years ago

I am automating my work flow with the following code:

import subprocess
import os

for root, dirs, files in os.walk('./content'):
    for filename in files:
        if filename.endswith(".md") and int(filename[:2]) > 9:
            md_name = f"{root}/{filename}"
            tex_name = f"{root}/../tex/section{filename[:2]}.tex"
            print(f'generating: {tex_name}...')
            subprocess.call([
                'pandoc', 
                '-r', 
                'markdown',
                md_name,
                '--filter',
                'pandoc-xnos',
                '-o',
                tex_name
            ])

when I run this via a Makefile, I get the following output.

PS C:\...> make
python ./src/convert_to_tex.py
generating: ./content/../tex/section10.tex...
Traceback (most recent call last):
  File "C:\...\python\current\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\...\python\current\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\...\python\current\Scripts\pandoc-xnos.exe\__main__.py", line 7, in <module>
  File "C:\...\python\current\lib\site-packages\pandocxnos\main.py", line 38, in main
    m.main(stdin, stdout)
  File "C:\...\python\current\lib\site-packages\pandoc_fignos.py", line 642, in main
    altered = functools.reduce(lambda x, action: walk(x, action, fmt, meta),
  File "C:\...\python\current\lib\site-packages\pandoc_fignos.py", line 642, in <lambda>
    altered = functools.reduce(lambda x, action: walk(x, action, fmt, meta),
  File "C:\...\python\current\lib\site-packages\pandocfilters.py", line 110, in walk
    res = action(item['t'],
  File "C:\...\python\current\lib\site-packages\pandocxnos\core.py", line 856, in process_refs
    _process_refs(value[-5], pattern, labels)
  File "C:\...\python\current\lib\site-packages\pandocxnos\core.py", line 92, in wrapper
    ret = func(*args, **kwargs)
  File "C:\...\python\current\lib\site-packages\pandocxnos\core.py", line 758, in _process_refs
    if v['t'] == 'Cite' and len(v['c']) == 2:
TypeError: string indices must be integers
Error running filter pandoc-xnos:
Filter returned error status 1
PS C:\...> make

Why would this be happening? This was working fine not too long ago. I suspect an update to Pandoc may have caused the problem but I wanted to check here. It should be noted that the code works fine without the --filter pandoc-xnos option.

dhimmel commented 4 years ago

Possibly related to https://github.com/tomduck/pandoc-fignos/issues/81. @flythereddflagg perhaps you can check if you get the error when using pandoc 2.9? I think 2.10 might have some AST changes that break things.

flythereddflagg commented 4 years ago

Reverting back to pandoc 2.9.2.1 did seem to fix the issue. What ever the problem is with the AST should be fixed in future versions.

tomduck commented 4 years ago

Thank you for posting this Issue. This was indeed owing to an AST change with pandoc 2.10. I have addressed the problems in the nextrelease branch. I expect to post a new release soon.

tomduck commented 4 years ago

P.S. Please do re-open this after the next release if the problem is not actually resolved.

dhimmel commented 4 years ago

This was indeed owing to an AST change with pandoc 2.10. I have addressed the problems in the nextrelease branch

Ah yes I see a related commit at https://github.com/tomduck/pandoc-xnos/commit/c8a27e7db6f50d89ebae62254c217997d344a986.

Much appreciation for your maintenance!

tomduck commented 4 years ago

Thanks @dhimmel. I am glad that the filters have been useful. :o) Cheers, Tom.