Skip to content

Commit

Permalink
Implemented support for internal <style> tags.
Browse files Browse the repository at this point in the history
* Closes #34.
  • Loading branch information
h3rald committed Jul 17, 2015
1 parent c62d09a commit fba8c20
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion doc/HastyScribe_UserGuide.htm

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions hastyscribe.nim
Expand Up @@ -24,7 +24,7 @@ let usage* = " HastyScribe v" & v & " - Self-contained Markdown Compiler" & """
--notoc Do not generate a Table of Contents.
--user-css=<file> Insert contents of <file> as a CSS stylesheet.
--output-file=<file> Write output to <file>.
(Use "--output-file=-" to output to stdout.)"""
(Use "--output-file=-" to output to stdout)"""


var generate_toc* = true
Expand Down Expand Up @@ -197,7 +197,7 @@ proc compile*(input_file: string) =
source = parse_snippets(source)

# Document Variables
var metadata = TMDMetaData(title:"", author:"", date:"")
var metadata = TMDMetaData(title:"", author:"", date:"", toc:"", css:"")
var body = source.md(MKD_DOTOC or MKD_EXTRA_FOOTNOTE, metadata)
var main_css_tag = stylesheet.style_tag
var user_css_tag = ""
Expand Down Expand Up @@ -243,6 +243,7 @@ proc compile*(input_file: string) =
$fonts_css_tag
$main_css_tag
$user_css_tag
$internal_css_tag
</head>
<body$headings>
<a id="document-top"></a>
Expand All @@ -256,7 +257,7 @@ $body
<p><span>Powered by</span> <a href="https://h3rald.com/hastyscribe"><span class="hastyscribe"></span></a></p>
</div>
</body>""" % ["title_tag", title_tag, "header_tag", header_tag, "author", metadata.author, "author_footer", author_footer, "date", timeinfo.format("MMMM d, yyyy"), "toc", toc, "main_css_tag", main_css_tag, "user_css_tag", user_css_tag, "headings", headings, "body", body,
"fonts_css_tag", embed_fonts()]
"fonts_css_tag", embed_fonts(), "internal_css_tag", metadata.css]
document = embed_images(document, inputsplit.dir)
document = add_jump_to_top_links(document)
if output_file != "-":
Expand Down
15 changes: 12 additions & 3 deletions markdown.nim
Expand Up @@ -123,11 +123,12 @@ const

# special flags for mkd_in() and mkd_string()

type TMDMetaData* = object of RootObj
type TMDMetaData* = object
title*: string
author*: string
date*: string
toc*: string
css*: string

proc md*(s: string, f = 0): string =
var flags = uint32(f)
Expand Down Expand Up @@ -161,18 +162,26 @@ proc md*(s: string, f = 0, data: var TMDMetadata): string =
data.author = $mkd_doc_author(mmiot)
data.date = $mkd_doc_date(mmiot)
discard mkd_compile(mmiot, flags)
# Process TOC
if (int(flags) and MKD_DOTOC) == MKD_DOTOC:
var toc = allocCStringArray([""])
discard $mkd_toc(mmiot, toc)
try:
discard mkd_toc(mmiot, toc)
data.toc = cstringArrayToSeq(toc)[0]
except:
data.toc = ""
# Process CSS
try:
var css = allocCStringArray([""])
discard mkd_css(mmiot, css)
data.css = cstringArrayToSeq(css)[0]
except:
data.css = ""
# Generate HTML
var res = allocCStringArray([""])
discard mkd_document(mmiot, res)
result = cstringArrayToSeq(res)[0]
mkd_cleanup(mmiot)
return

when defined(macosx):
{.link: "vendor/libmarkdown_macosx_x64.a".}
Expand Down

0 comments on commit fba8c20

Please sign in to comment.