]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blobdiff - rpp/blocks/scripts/doc_parse.py
doc: Allow underscores (and markdown syntax) in parameter documentation
[pes-rpp/rpp-simulink.git] / rpp / blocks / scripts / doc_parse.py
index 669b5240c535964ac3fc7ce5156d1fbbf5d4dea6..1ccb38c57deac00181ab364d3516788aaaa257b2 100755 (executable)
@@ -1,6 +1,6 @@
 #!/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>
@@ -19,6 +19,7 @@ import Rx
 import sys
 import subprocess
 import os
+import os.path
 from string import Template
 
 parser = argparse.ArgumentParser()
@@ -43,30 +44,35 @@ args = parser.parse_args()
 
 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("\\subsubsection{%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']))
@@ -76,13 +82,13 @@ def print_latex_desc(doc):
     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}")
@@ -117,7 +123,7 @@ def process_file(f):
     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']=''