diff --git a/.gitignore b/.gitignore index 89b8b81..20f01d3 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ hackpack.pdf +hackpack.html diff --git a/cyber.html b/cyber.html new file mode 100644 index 0000000..5641ecb --- /dev/null +++ b/cyber.html @@ -0,0 +1,67 @@ + + + + + + +$for(author-meta)$ + +$endfor$ +$if(date-meta)$ + +$endif$ +$if(keywords)$ + +$endif$ + $if(title-prefix)$$title-prefix$ – $endif$$pagetitle$ + +$if(quotes)$ + +$endif$ +$if(highlighting-css)$ + +$endif$ +$for(css)$ + +$endfor$ +$if(math)$ + $math$ +$endif$ + +$for(header-includes)$ + $header-includes$ +$endfor$ + + +$for(include-before)$ +$include-before$ +$endfor$ +$if(title)$ +
+

$title$

+$if(subtitle)$ +

$subtitle$

+$endif$ +$for(author)$ +

$author$

+$endfor$ +$if(date)$ +

$date$

+$endif$ +
+$endif$ +$if(toc)$ + +$endif$ +$body$ +$for(include-after)$ +$include-after$ +$endfor$ + + diff --git a/html.py b/html.py new file mode 100755 index 0000000..b33979c --- /dev/null +++ b/html.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 +import json +import sys + +from pandocfilters import walk, Header, Link, Para, Str + + +depth = 0 +jump = Para([Link(['', [], []], [Str('Jump to Top')], ('#', 'top'))]) + + +def add_to_headers(key, val, fmt, meta): + global depth + + if key == 'Header': + lvl, attr, inline = val + + if lvl > depth: + depth += 1 + return + elif lvl < depth: + depth = lvl + + if lvl <= 3: + return [jump, Header(lvl, attr, inline)] + + +def jump_to_top(doc, fmt): + doc = walk(doc, add_to_headers, fmt, doc['meta'] if 'meta' in doc else {}) + + doc['blocks'].append(jump) + + return doc + + +if __name__ == "__main__": + json.dump(jump_to_top(json.load(sys.stdin), sys.argv[1] if len(sys.argv) > 1 else ''), sys.stdout) diff --git a/makefile b/makefile index 77a8f07..9ffeefc 100644 --- a/makefile +++ b/makefile @@ -1,8 +1,9 @@ SHELL=/bin/bash -OUTFILE=hackpack.pdf +OUTFILE=hackpack.html -TEMPLATE=./cyber.latex +FILTER=./html.py +TEMPLATE=./cyber.html HIGHLIGHT_STYLE=tango FIND=./find.py @@ -22,7 +23,7 @@ clean: rm -f "$(OUTFILE)" $(OUTFILE): $(SOURCES) - pandoc --template="$(TEMPLATE)" --highlight-style="${HIGHLIGHT_STYLE}" --standalone --toc --output "$(OUTFILE)" $(SOURCES) + pandoc --filter="$(FILTER)" --template="$(TEMPLATE)" --highlight-style="${HIGHLIGHT_STYLE}" --standalone --toc --output "$(OUTFILE)" $(SOURCES) $(WEBSITE)/$(OUTFILE): $(OUTFILE) cp $(OUTFILE) $(WEBSITE)/documents/