all repos — hastyscribe @ bfa68e5d7bd0ff126c252212ad381bb2a01c9133

A professional markdown compiler.

Added support for document metadata
h3rald h3rald@h3rald.com
Sun, 22 Sep 2013 20:35:17 +0200
commit

bfa68e5d7bd0ff126c252212ad381bb2a01c9133

parent

b76fc25c7b8a6a0bdfe879c09ae47c812eb05a2b

3 files changed, 25 insertions(+), 5 deletions(-)

jump to
M hastyscribe.nimhastyscribe.nim

@@ -27,13 +27,17 @@

let source = input_file.readFile # Document Variables -let body = source.md(MKD_DOTOC or MKD_EXTRA_FOOTNOTE) +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>

@@ -42,6 +46,6 @@ <div class="pure-u">

$body </div> </div> -</body>""" % ["css", css, "body", body] +</body>""" % ["title", metadata.title, "author", metadata.author, "date", metadata.date, "css", css, "body", body] output_file.writeFile(document)
M markdown.nimmarkdown.nim

@@ -124,13 +124,29 @@ MKD_EMBED* = MKD_NOLINKS or MKD_NOIMAGE or MKD_TAGTEXT

# special flags for mkd_in() and mkd_string() +type TMDMetaData* = object of TObject + title*: string + author*: string + date*: string + proc md*(s: string, f = 0): string = var flags = uint32(f) var str = cstring(s) var mmiot = mkd_string(str, cint(str.len-1), flags) - discard mkd_doc_title(mmiot) - discard mkd_doc_author(mmiot) - discard mkd_doc_date(mmiot) + discard mkd_compile(mmiot, flags) + var res = allocCStringArray([""]) + discard mkd_document(mmiot, res) + result = cstringArrayToSeq(res)[0] + mkd_cleanup(mmiot) + return + +proc md*(s: string, f = 0, data: var TMDMetadata): string = + var flags = uint32(f) + var str = cstring(s) + var mmiot = mkd_string(str, cint(str.len-1), flags) + data.title = $mkd_doc_title(mmiot) + data.author = $mkd_doc_author(mmiot) + data.date = $mkd_doc_date(mmiot) discard mkd_compile(mmiot, flags) var res = allocCStringArray([""]) discard mkd_document(mmiot, res)