Pandoc

From ActiveArchives
Jump to: navigation, search

Calling pandoc from python

def pandoc (text):
    pargs = []
    pargs.append("pandoc")
    pargs.append("--from")
    pargs.append("markdown-blank_before_header+lists_without_preceding_blankline+hard_line_breaks")
    pargs.append("--to")
    pargs.append("html5")
    pargs.append("--standalone")
    pargs.append("--smart")
    pargs.append("--section-divs")
    # for some reason shell=False was necessary to getting the options to be taken, not really sure why
    p = subprocess.Popen(pargs, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
    stdout, stderr = p.communicate(text.encode("utf-8"), timeout=5)
    return stdout.decode("utf-8"), stderr.decode("utf-8")

call inkscape with live xml source...

def make_title(template, text, output):
    template = ET.parse(template)
    fp = template.find(".//{http://www.w3.org/2000/svg}flowPara") # 
    fp.text = text
    ET.register_namespace('',"http://www.w3.org/2000/svg") #some name
    xml = ET.tostring(template.getroot(), encoding="unicode")
 
    cmd = ["inkscape",]
    cmd.append("--export-png={0}".format(output))
    cmd.append("--export-background-opacity=0")
    cmd.append("/dev/stdin")
 
    p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
    stdout, stderr = p.communicate(xml.encode("utf-8"), timeout=5)
    stdout, stderr = stdout.decode("utf-8"), stderr.decode("utf-8")
    print (stdout, stderr)
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox