all repos — hastyscribe @ 2d740d83cc846b20c46cddbfcf56116c48f1781e

A professional markdown compiler.

Expose more functions as public:
- preprocessing of markdown files
- adding icons for jumping to the top of the page
kaminski kaminski@naew.nato.int
Thu, 01 Apr 2021 00:45:56 +0200
commit

2d740d83cc846b20c46cddbfcf56116c48f1781e

parent

8ac9afc750354133311c4020209f8c377187e073

2 files changed, 6 insertions(+), 7 deletions(-)

jump to
M src/hastyscribe.nimsrc/hastyscribe.nim

@@ -153,10 +153,6 @@ let imgrep = img.replace("\"" & img_file & "\"", "\"" & imgcontent & "\"")

doc = doc.replace(img, imgrep) hs.document = doc -proc add_jump_to_top_links(hs: var HastyScribe) = - hs.document = hs.document.replacef(peg"{'</h' [23456] '>'}", "<a href=\"#document-top\" title=\"Go to top\"></a>$1") - - proc embed_fonts(): string= let fonts = @[ create_font_face(hastyscribe_font, "HastyScribe", "normal", 400),

@@ -173,7 +169,7 @@ create_font_face(sourcesanspro_boldit_font, "Source Sans Pro", "italic", 700)

] return style_tag(fonts.join); -proc preprocess(hs: var HastyScribe, document, dir: string, offset = 0): string +proc preprocess*(hs: var HastyScribe, document, dir: string, offset = 0): string proc applyHeadingOffset(contents: string, offset: int): string = if offset == 0:

@@ -346,7 +342,7 @@ discard anchor.match(peg_anchor, matches)

var id = matches[0] result = result.replace(anchor, " <a id=\""&id&"\"></a>") -proc preprocess(hs: var HastyScribe, document, dir: string, offset = 0): string = +proc preprocess*(hs: var HastyScribe, document, dir: string, offset = 0): string = result = hs.parse_transclusions(document, dir, offset) result = hs.parse_fields(result) result = hs.parse_snippets(result)

@@ -465,7 +461,7 @@ $js

</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", hs.document, "fonts_css_tag", embed_fonts(), "internal_css_tag", metadata.css, "watermark_css_tag", watermark_css_tag, "js", user_js_tag] hs.embed_images(dir) - hs.add_jump_to_top_links() + hs.document = add_jump_to_top_links(hs.document) return hs.document proc compile*(hs: var HastyScribe, input_file: string) =
M src/hastyscribepkg/utils.nimsrc/hastyscribepkg/utils.nim

@@ -33,6 +33,9 @@ else:

let img = imgfile.encode_image_file(imgfile.image_format) result = (watermark_style % [img]).style_tag +proc add_jump_to_top_links*(document: string): string = + result = document.replacef(peg"{'</h' [23456] '>'}", "<a href=\"#document-top\" title=\"Go to top\"></a>$1") + proc encode_font*(font, format: string): string = let enc_contents = font.encode return "data:application/$format;charset=utf-8;base64,$enc_contents" % ["format", format, "enc_contents", enc_contents]