Add a pandoc filter to create compatible html.

This commit is contained in:
Oliver Buchtala 2014-02-14 00:01:15 +01:00
commit 8148b017f8
2 changed files with 63 additions and 50 deletions

59
Doc/Manual/pandoc_filter.py Executable file
View file

@ -0,0 +1,59 @@
#!/usr/bin/env python
"""
Pandoc filter that changes pandoc default HTML output for codeblocks
to match SWIG's format:
<div class="...">
<pre>...</pre>
</div>
"""
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('<pre>\n' + contents + '</pre>')]
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)

View file

@ -1,56 +1,10 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"$if(lang)$ lang="$lang$" xml:lang="$lang$"$endif$>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta name="generator" content="pandoc" />
$for(author-meta)$
<meta name="author" content="$author-meta$" />
$endfor$
$if(date-meta)$
<meta name="date" content="$date-meta$" />
$endif$
<title>$if(title-prefix)$$title-prefix$ - $endif$$if(pagetitle)$$pagetitle$$endif$</title>
$if(highlighting-css)$
<style type="text/css">
$highlighting-css$
</style>
$endif$
$for(css)$
<link rel="stylesheet" href="$css$" $if(html5)$$else$type="text/css" $endif$/>
$endfor$
$if(math)$
$math$
$endif$
$for(header-includes)$
$header-includes$
$endfor$
<link rel="stylesheet" type="text/css" href="./style.css">
<title>$pagetitle$</title>
</head>
<body>
$for(include-before)$
$include-before$
$endfor$
$if(title)$
<div id="$idprefix$header">
<h1 class="title">$title$</h1>
$for(author)$
<h2 class="author">$author$</h2>
$endfor$
$if(date)$
<h3 class="date">$date$</h3>
$endif$
</div>
$endif$
$if(toc)$
<div class="sectiontoc">
$toc$
</div>
$endif$
<div>
$body$
</div>
$for(include-after)$
$include-after$
$endfor$
</body>
</html>