#!/usr/bin/env python3
-# Copyright (C) 2013-2014 Czech Technical University in Prague
+# Copyright (C) 2013-2015 Czech Technical University in Prague
#
# Authors:
# - Michal Sojka <sojkam1@fel.cvut.cz>
import sys
import subprocess
import os
+import os.path
from string import Template
parser = argparse.ArgumentParser()
mydir = os.path.dirname(os.path.realpath(__file__))
-def print_markdown_as(format, text):
+def markdown_as(format, text):
sys.stdout.flush()
- proc = subprocess.Popen(['pandoc', '-f', 'markdown', '-t', format], stdin = subprocess.PIPE)
+ proc = subprocess.Popen(['pandoc', '-f', 'markdown', '-t', format], stdin = subprocess.PIPE, stdout = subprocess.PIPE)
proc.stdin.write(bytes(text, 'UTF-8'))
- proc.communicate()
+ (stdout, stderr) = proc.communicate()
proc.stdin.close()
if proc.returncode:
raise Exception("pandoc failed: %d" % proc.returncode)
+ return stdout.decode('utf-8').rstrip()
+
+def print_markdown_as(format, text):
+ print(markdown_as(format, text))
-def print_latex_desc(doc):
+def print_latex_desc(doc, filename):
def iodef_str(iodef):
if iodef is None: return "None"
str='%d\n\\begin{enumerate}\n' % len(iodef)
for io in iodef:
str += Template('\\item {\\bf $name} $type').substitute(io)
if 'range' in io:
- str += ' %s' % io['range']
+ str += ' %s' % markdown_as('latex', io['range'])
if 'note' in io:
- str += ' %s' % io['note']
+ str += ' %s' % markdown_as('latex', io['note'])
str += '\n'
return str +'\end{enumerate}'
print("\\newpage\n")
- print("\\subsection{%s}\n" % doc['Name'])
+ print("\\subsection{%s}" % doc['Name'])
+ print("\\label{sec:block:%s}\n" % os.path.basename(filename))
print("\\begin{description}\n")
print("\\item[Inputs:] %s\n" % iodef_str(doc['Inputs']))
print("\\item[Outputs:] %s\n" % iodef_str(doc['Outputs']))
print_markdown_as('latex', doc['Help'])
if doc.get('RPP API functions used', None) is not None:
- print("\\textbf{RPP API functions used:}")
+ print("\\paragraph{RPP API functions used:}")
print("\\begin{compactitem}")
print("\n".join(["\\item \\texttt{%s}" % i.replace('_', '\\_') for i in doc['RPP API functions used']]))
print("\\end{compactitem}")
if doc.get('Relevant demos', None) is not None:
- print("\\textbf{Relevant demos:}")
+ print("\\paragraph{Relevant demos:}")
print("\\begin{compactitem}")
print("\n".join(["\\item %s" % i.replace('_', '\\_') for i in doc['Relevant demos']]))
print("\\end{compactitem}")
if args.printhelp:
print_markdown_as(fmt, doc['Help'])
if args.latex:
- print_latex_desc(doc)
+ print_latex_desc(doc, f)
if args.latex_table:
global last_category
if last_category == doc['Category']: doc['Category']=''