Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Strange Pandoc Error
#1
Hi everyone I am trying to troubleshoot this issue as it is not apparent to me why the filter is failing.
Many thanks if anyone can solve the issue!

pandoc -f markdown --filter /tmp/creation/pandoc_filters/include_markdown.py --filter /tmp/creation/pandoc_filters/convert_link_ext.py --filter /tmp/creation/pandoc_filters/include_code.py -t html5 -s --toc --toc-depth=3 --section-divs -c ./css/notes_toc.css -H /tmp/creation/page_includes/bc.html -o publish/index.html.html source/index.html.md
Quote:pandoc: Error running filter /tmp/creation/pandoc_filters/include_markdown.py

Here is the source of include_markdown.py

import os
import panflute as pf


def is_include_line(elem):
    if len(elem.content) < 3:
        return False
    elif not all (isinstance(x, (pf.Str, pf.Space)) for x in elem.content):
        return False
    elif elem.content[0].text != '$include':
        return False
    elif type(elem.content[1]) != pf.Space:
        return False
    else:
        return True

def get_filename(elem):
    fn = pf.stringify(elem, newlines=False).split(None,1)[1]
    print fn
    if not os.path.splitext(fn)[1]:
        fn += '.md'
    return fn


def action(elem, doc):
    if isinstance(elem, pf.Para) and is_include_line(elem):
        
        fn = get_filename(elem)
        if not os.path.isfile(fn):
            return
        
        with open(fn) as f:
            raw = f.read()

        new_elems = pf.convert_text(raw)
        
        # Alternative A:
        return new_elems
        # Alternative B:
        # div = pf.Div(*new_elems, attributes={'source': fn})
        # return div


def main(doc=None):
    return pf.run_filter(action, doc=doc) 


if __name__ == '__main__':
    main()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Strange argument count error rowan_bradley 3 659 Aug-06-2023, 10:58 AM
Last Post: rowan_bradley
  Converting several Markdown files into DOCX using Pandoc Akule8 0 1,157 Feb-02-2023, 02:54 PM
Last Post: Akule8
  Strange error ValueError: dimension mismatch Anldra12 0 1,937 Aug-17-2021, 07:54 AM
Last Post: Anldra12
  Strange syntax error with f-strings Askic 6 4,078 Oct-16-2020, 10:40 AM
Last Post: Askic
  Very strange error of indentation samsonite 12 5,125 Mar-22-2019, 10:45 AM
Last Post: samsonite

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020