Skip to content

Commit

Permalink
add basic html generation
Browse files Browse the repository at this point in the history
  • Loading branch information
lilyinstarlight committed Jul 17, 2017
1 parent 20f0d56 commit 9fb7846
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
hackpack.pdf
hackpack.html
67 changes: 67 additions & 0 deletions cyber.html
@@ -0,0 +1,67 @@
<!DOCTYPE html>
<html$if(lang)$ lang="$lang$"$endif$$if(dir)$ dir="$dir$"$endif$>
<head>
<meta charset="utf-8">
<meta name="generator" content="pandoc">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
$for(author-meta)$
<meta name="author" content="$author-meta$">
$endfor$
$if(date-meta)$
<meta name="dcterms.date" content="$date-meta$">
$endif$
$if(keywords)$
<meta name="keywords" content="$for(keywords)$$keywords$$sep$, $endfor$">
$endif$
<title>$if(title-prefix)$$title-prefix$ – $endif$$pagetitle$</title>
<style type="text/css">code{white-space: pre;}</style>
$if(quotes)$
<style type="text/css">q { quotes: "“" "”" "‘" "’"; }</style>
$endif$
$if(highlighting-css)$
<style type="text/css">
$highlighting-css$
</style>
$endif$
$for(css)$
<link rel="stylesheet" href="$css$">
$endfor$
$if(math)$
$math$
$endif$
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
<![endif]-->
$for(header-includes)$
$header-includes$
$endfor$
</head>
<body>
$for(include-before)$
$include-before$
$endfor$
$if(title)$
<header>
<h1 class="title">$title$</h1>
$if(subtitle)$
<p class="subtitle">$subtitle$</p>
$endif$
$for(author)$
<p class="author">$author$</p>
$endfor$
$if(date)$
<p class="date">$date$</p>
$endif$
</header>
$endif$
$if(toc)$
<nav id="$idprefix$TOC">
$toc$
</nav>
$endif$
$body$
$for(include-after)$
$include-after$
$endfor$
</body>
</html>
37 changes: 37 additions & 0 deletions 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)
7 changes: 4 additions & 3 deletions 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
Expand All @@ -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/
Expand Down

0 comments on commit 9fb7846

Please sign in to comment.