hastyscribe.nim
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import os, parseopt, strutils, markdown # Source const src_css = "assets/hastyscribe.css".slurp proc style_tag(css): string = result = "<style>$1</style>" % [css] let css = src_css.style_tag ### MAIN var opt = initOptParser() opt.next if opt.kind != cmdArgument: quit() # Input file name let input_file = opt.key let inputsplit = input_file.splitFile # Output file name let output_file = inputsplit.dir/inputsplit.name & ".htm" let source = input_file.readFile # Document Variables var metadata = TMDMetaData(title:"", author:"", date:"") let body = source.md(MKD_DOTOC or MKD_EXTRA_FOOTNOTE, metadata) let document = """<!doctype html> <html lang="en"> <head> <title>$title</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="author" content="$author"> <meta name="date" content="$date" scheme="YYYY-MM-DD"> $css </head> <body> <h1>$title</h1> <div id="toc"> $toc </nav> <div> $body </main> <div id="footer"> <p>by $author – Generated with <a href="http://h3rald.com/hastyscribe/">HastyScribe</a></p> </div> </body>""" % ["title", metadata.title, "author", metadata.author, "date", metadata.date, "toc", metadata.toc, "css", css, "body", body] output_file.writeFile(document) |