diff --git a/Doc/Manual/pandoc_filter.py b/Doc/Manual/pandoc_filter.py new file mode 100755 index 000000000..81b259936 --- /dev/null +++ b/Doc/Manual/pandoc_filter.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python + +""" +Pandoc filter that changes pandoc default HTML output for codeblocks +to match SWIG's format: + +
+
...
+
+ +""" + +from pandocfilters import toJSONFilter, stringify, walk, RawBlock, Div, Str +import sys +import json +import re + +global the_title + +def html(x): + return RawBlock('html', x) + +SHELL = re.compile(r"\s*[$]") + +def codeblocks(key, value, format, meta): + if key == 'CodeBlock': + [[id, classes, kvs], contents] = value + if format == "html" or format == "html5": + newcontents = [html('
\n' + contents + '
')] + + if contents.startswith("$"): + classes.append("shell") + + if len(classes) == 0: + classes.append("code") + + return Div([id, classes, kvs], newcontents) + if key == 'Header': + if value[0] == 1: + global the_title + the_title = stringify(value) + value[1][0] = "" + +def set_title(unMeta): + global the_title + unMeta["title"] = {"t": "MetaInlines", "c": [Str(the_title)]} + +def __toJSONFilter(action): + doc = json.loads(sys.stdin.read()) + if len(sys.argv) > 1: + format = sys.argv[1] + else: + format = "" + altered = walk(doc, action, format, doc[0]['unMeta']) + set_title(altered[0]['unMeta']) + json.dump(altered, sys.stdout) + +if __name__ == "__main__": + __toJSONFilter(codeblocks) diff --git a/Doc/Manual/pandoc_template.html b/Doc/Manual/pandoc_template.html index 390bfc51c..d8cbc12ad 100644 --- a/Doc/Manual/pandoc_template.html +++ b/Doc/Manual/pandoc_template.html @@ -1,56 +1,10 @@ - - + + - - - -$for(author-meta)$ - -$endfor$ -$if(date-meta)$ - -$endif$ - $if(title-prefix)$$title-prefix$ - $endif$$if(pagetitle)$$pagetitle$$endif$ -$if(highlighting-css)$ - -$endif$ -$for(css)$ - -$endfor$ -$if(math)$ - $math$ -$endif$ -$for(header-includes)$ - $header-includes$ -$endfor$ + + $pagetitle$ -$for(include-before)$ -$include-before$ -$endfor$ -$if(title)$ -
-

$title$

-$for(author)$ -

$author$

-$endfor$ -$if(date)$ -

$date$

-$endif$ -
-$endif$ -$if(toc)$ -
-$toc$ -
-$endif$ -
$body$ -
-$for(include-after)$ -$include-after$ -$endfor$