all repos — hastyscribe @ 6853b975208d331453cad6cc8300bb84e4a040de

A professional markdown compiler.

Implemented system fields.
* Closes #39.
h3rald h3rald@h3rald.com
Sat, 11 Jun 2016 11:32:34 +0200
commit

6853b975208d331453cad6cc8300bb84e4a040de

parent

50ccba2fa4d0ecd5d59723edcbf1a39168aa32b4

4 files changed, 262 insertions(+), 7 deletions(-)

jump to
M doc/HastyScribe_UserGuide.htmdoc/HastyScribe_UserGuide.htm

@@ -81,6 +81,7 @@ <ul>

<li><a href="#Standard.Markdown">Standard Markdown</a></li> <li><a href="#Discount.Extensions">Discount Extensions</a></li> <li><a href="#Text.Snippets">Text Snippets</a></li> + <li><a href="#Custom.Fields">Custom Fields</a></li> <li><a href="#Image..and.font..Embedding">Image (and font) Embedding</a></li> <li><a href="#FontAwesome.Icons">FontAwesome Icons</a></li> <li><a href="#Notes..tips..warnings..sidebars.and.badges">Notes, tips, warnings, sidebars and badges</a></li>

@@ -109,6 +110,7 @@ <li><a href="#Syntax.Reference">Syntax Reference</a>

<ul> <li><a href="#Document.Headers">Document Headers</a></li> <li><a href="#Snippets">Snippets</a></li> + <li><a href="#Fields">Fields</a></li> <li><a href="#Inline.Formatting">Inline Formatting</a> <ul> <li><a href="#SmartyPants.Substitutions">SmartyPants Substitutions</a></li>

@@ -202,6 +204,10 @@ <h4 id="Text.Snippets">Text Snippets<a href="#document-top" title="Go to top"></a></h4>

<p>Although not part of neither markdown nor Discount, HastyScribe allows you to create text <a href="#Snippets">snippets</a> to reuse content. Useful when you have to use a sentence or a formatted block of text over and over in a document, or shorten long words (like the word <em>HastyScribe</em> in this document <span class="fa-smile-o"></span>).</p> +<h4 id="Custom.Fields">Custom Fields<a href="#document-top" title="Go to top"></a></h4> + +<p>HastyScribe also supports <a href="#Fields">fields</a> to easily include things like the current date or time, but also custom values specified as command-line parameters.</p> + <h4 id="Image..and.font..Embedding">Image (and font) Embedding<a href="#document-top" title="Go to top"></a></h4> <p>HastyScribe only produces single HTML files. With <em>no dependencies</em>:</p>

@@ -300,7 +306,7 @@ <li><em>filename-or-glob-expression</em> is a valid file or <a href="http://en.wikipedia.org/wiki/Glob_(programming">glob</a>) expression that will be compiled into HTML.</li>

<li>The following options are supported: <ul> -<li><span class="opt">--notoc</span> causes HastyScribe to output HTML documents <em>without</em> automatically generated a Table of Contents at the start.</li> +<li><span class="opt">--notoc</span> causes HastyScribe to output HTML documents <em>without</em> automatically generating a Table of Contents at the start.</li> <li><span class="opt">--user-css=&lt;file></span> causes HastyScribe inserts the contents of the specified local file as a CSS stylesheet.</li> <li><span class="opt">--output-file=&lt;file></span> causes HastyScribe to write output to a local file (Use <span class="opt">--output-file=-</span> to output to standard output).</li> </ul>

@@ -369,6 +375,110 @@ <ul>

<li>It doesn&rsquo;t matter where a snippet is defined. Snippets can be used anywhere in the document, before or after their definition.</li> <li>When a document is compiled, both snippets <em>and snippets definitions</em> are evaluated their body text.</li> </ul> +</div> + +<h3 id="Fields">Fields<a href="#document-top" title="Go to top"></a></h3> + +<p>Besides user-defined snippets, HastyScribe also support fields, which can be used to insert current time and date information in a variety of formats:</p> + +<div class="responsive"><table> +<thead> +<tr> +<th>Source </th> +<th> Output</th> +</tr> +</thead> +<tbody> +<tr> +<td><code>{{$timestamp}}</code> </td> +<td> 1465637520</td> +</tr> +<tr> +<td><code>{{$date}}</code> </td> +<td> 2016-06-11</td> +</tr> +<tr> +<td><code>{{$full-date}}</code> </td> +<td> Saturday, June 11, 2016</td> +</tr> +<tr> +<td><code>{{$long-date}}</code> </td> +<td> June 11, 2016</td> +</tr> +<tr> +<td><code>{{$medium-date}}</code> </td> +<td> Jun 11, 2016</td> +</tr> +<tr> +<td><code>{{$short-date}}</code> </td> +<td> 6/11/16</td> +</tr> +<tr> +<td><code>{{$short-time}}</code> </td> +<td> 11:32 AM</td> +</tr> +<tr> +<td><code>{{$short-time-24}}</code> </td> +<td> 11:32</td> +</tr> +<tr> +<td><code>{{$time}}</code> </td> +<td> 11:32:00 AM</td> +</tr> +<tr> +<td><code>{{$time-24}}</code> </td> +<td> 11:32:00</td> +</tr> +<tr> +<td><code>{{$day}}</code> </td> +<td> 11</td> +</tr> +<tr> +<td><code>{{$short-day}}</code> </td> +<td> 11</td> +</tr> +<tr> +<td><code>{{$month}}</code> </td> +<td> 06</td> +</tr> +<tr> +<td><code>{{$short-month}}</code> </td> +<td> 6</td> +</tr> +<tr> +<td><code>{{$year}}</code> </td> +<td> 2016</td> +</tr> +<tr> +<td><code>{{$short-year}}</code> </td> +<td> 16</td> +</tr> +<tr> +<td><code>{{$weekday}}</code> </td> +<td> Saturday</td> +</tr> +<tr> +<td><code>{{$weekday-abbr}}</code> </td> +<td> 11</td> +</tr> +<tr> +<td><code>{{$month-name}}</code> </td> +<td> June</td> +</tr> +<tr> +<td><code>{{$month-name-abbr}}</code> </td> +<td> Jun</td> +</tr> +<tr> +<td><code>{{$timezone}}</code> </td> +<td> CEST</td> +</tr> +<tr> +<td><code>{{$timezone-offset}}</code> </td> +<td> -01:00</td> +</tr> +</tbody> +</table> </div> <h3 id="Inline.Formatting">Inline Formatting<a href="#document-top" title="Go to top"></a></h3>

@@ -1202,7 +1312,7 @@

<p style="text-align:center;"> <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFgAAAAfCAYAAABjyArgAAAGa0lEQVRo3u1aW08bRxTmuSqIV0SlIFWtAKkVtEpfWiVI6Q+gT60qpeIhTXkrSpqoaZ1AkJMobSRkkUahEtAWCVWBYMDcfME22MZ3rw0hrzzwAxC/4FTfrGeYXXa9u8Y0yGGkEeu5nGW+OfOdy2wDETU1NDTQea19JcKf8o/lwBKthlbIH16j0EaQwrEwbSSiFEvFaCuToFQuSel8mrKFDOWULOWKObUqWcoqGcrk02wMxsZTMTY3EgszWf6wn8nGO3xri7SwOk/zy16aW3pJL32zrM4uztDMwou6qRLQR+AGIn5a3wxRNB6hWHKTgZXOpxiAhVKeijsKlV4VaXt3m3ZeqxXPpVcl1ocxWSXL5mAuZEQTESYTsvUge5fnBMgA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W3KuX7tmWG0bOfi+yCvwBQFE/SKNONkOX8snAO+AT7yV2RIAD96/J9wiuwBbuVcyPbjvDws3DS4btNqpnBO7aW8SYAQc3FWzE2hwrnMSIDz57fdjgUY1cipxb8VAwy5FwPDBdcMzQJUpQt9nlyIA8PSL6foOlSsZuUqGzI6R4zusGrkie5ds5ADwUsBHU/9OabJW2DTIwXw5aLFK0gAcOUnzJuUcc9N4iAzXSn/Mzdw0gMzb9X0o0GjZTUtLblogEhCZNZYfXpqjX+7WYbqSBxpymKz3Z2sZaGyWAw2kLnlWjact6+l2QwCcSBuHyk7i8WpDZTn5XrcAy8meib/Ga5/sGfUw2Uj24F08ZSkn3vnNRj1dHQmAUV2DLpGuvPrdVQ3ITpI+0HrDdGUhQ8MPht/G2+WjHwM3fmRuVLGKhDv6MEZOuF/87CKjBvjZrnLe960GGBUJcAQDAFnW5GqujABuvpijZ2PP7H5HYBhk6MfYkWP22yyZ5EROpaSUJcACZEW99AQnO770HOWXnlnb4BoBYbQwJxtVab7djaqBHOMO0IV8bQ/QrK7tcXPBru3xfUQh45gWrNKVTjfK7G8t5VQNMLvf+rSbvIte5sLBT1bEhycl6cOTEmuTPzyZ93np0uVL1XxqdCJqsKKEajS4BnKs/2GA9fjJYwpFQ9KnU+WKT6cKGdaHMdUAe1oafGY5+LzWsBLRO+dAnN7Xlf8BOGLNYHeHmZwAAAAASUVORK5CYII=" alt="Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License" /></p> </div> <div id="footer"> - <p><span class="copy"></span> Fabio Cevasco &ndash; September 6, 2015</p> + <p><span class="copy"></span> Fabio Cevasco &ndash; June 11, 2016</p> <p><span>Powered by</span> <a href="https://h3rald.com/hastyscribe"><span class="hastyscribe"></span></a></p> </div> </body>
M doc/HastyScribe_UserGuide.mddoc/HastyScribe_UserGuide.md

@@ -43,6 +43,10 @@ #### Text Snippets

Although not part of neither {{md}} nor Discount, {{hs}} allows you to create text [snippets](#Snippets) to reuse content. Useful when you have to use a sentence or a formatted block of text over and over in a document, or shorten long words (like the word _{{hs}}_ in this document [](class:fa-smile-o)). +#### Custom Fields + +{{hs}} also supports [fields](#Fields) to easily include things like the current date or time, but also custom values specified as command-line parameters. + #### Image (and font) Embedding {{hs}} only produces single HTML files. With _no dependencies_:

@@ -129,7 +133,7 @@ Where:

* _filename-or-glob-expression_ is a valid file or [glob](http://en.wikipedia.org/wiki/Glob_(programming)) expression that will be compiled into HTML. * The following options are supported: - * [\-\-notoc](class:opt) causes {{hs}} to output HTML documents _without_ automatically generated a Table of Contents at the start. + * [\-\-notoc](class:opt) causes {{hs}} to output HTML documents _without_ automatically generating a Table of Contents at the start. * [\-\-user-css=<file\>](class:opt) causes {{hs}} inserts the contents of the specified local file as a CSS stylesheet. * [\-\-output-file=<file\>](class:opt) causes {{hs}} to write output to a local file (Use [\-\-output-file=-](class:opt) to output to standard output).

@@ -198,6 +202,36 @@ > Remarks

> > * It doesn't matter where a snippet is defined. Snippets can be used anywhere in the document, before or after their definition. > * When a document is compiled, both snippets _and snippets definitions_ are evaluated their body text. + +### Fields + +Besides user-defined snippets, {{hs}} also support fields, which can be used to insert current time and date information in a variety of formats: + +> %responsive% +> Source | Output +> --------------------------------------------|---------------------- +> <code>\{\{$timestamp\}\}</code> | {{$timestamp}} +> <code>\{\{$date\}\}</code> | {{$date}} +> <code>\{\{$full-date\}\}</code> | {{$full-date}} +> <code>\{\{$long-date\}\}</code> | {{$long-date}} +> <code>\{\{$medium-date\}\}</code> | {{$medium-date}} +> <code>\{\{$short-date\}\}</code> | {{$short-date}} +> <code>\{\{$short-time\}\}</code> | {{$short-time}} +> <code>\{\{$short-time-24\}\}</code> | {{$short-time-24}} +> <code>\{\{$time\}\}</code> | {{$time}} +> <code>\{\{$time-24\}\}</code> | {{$time-24}} +> <code>\{\{$day\}\}</code> | {{$day}} +> <code>\{\{$short-day\}\}</code> | {{$short-day}} +> <code>\{\{$month\}\}</code> | {{$month}} +> <code>\{\{$short-month\}\}</code> | {{$short-month}} +> <code>\{\{$year\}\}</code> | {{$year}} +> <code>\{\{$short-year\}\}</code> | {{$short-year}} +> <code>\{\{$weekday\}\}</code> | {{$weekday}} +> <code>\{\{$weekday-abbr\}\}</code> | {{$weekday-abbr}} +> <code>\{\{$month-name\}\}</code> | {{$month-name}} +> <code>\{\{$month-name-abbr\}\}</code> | {{$month-name-abbr}} +> <code>\{\{$timezone\}\}</code> | {{$timezone}} +> <code>\{\{$timezone-offset\}\}</code> | {{$timezone-offset}} ### Inline Formatting
M hastyscribe.nimhastyscribe.nim

@@ -55,6 +55,95 @@ peg_snippet = peg"""

snippet <- '{{' \s* {id} \s* '}}' id <- [a-zA-Z0-9_-]+ """ + peg_field = peg""" + field <- '{{' \s* '$' {id} \s* '}}' + id <- [a-zA-Z0-9_-]+ + """ + +var FIELDS = initTable[string, proc():string]() + + +var NOW:TimeInfo + +FIELDS["timestamp"] = proc():string = + return $NOW.toTime.toSeconds().int + + + +FIELDS["date"] = proc():string = + return $NOW.format("yyyy-MM-dd") + +FIELDS["full-date"] = proc():string = + return $NOW.format("dddd, MMMM d, yyyy") + +FIELDS["long-date"] = proc():string = + return $NOW.format("MMMM d, yyyy") + +FIELDS["medium-date"] = proc():string = + return $NOW.format("MMM d, yyyy") + +FIELDS["short-date"] = proc():string = + return $NOW.format("M/d/yy") + + + +FIELDS["short-time-24"] = proc():string = + return $NOW.format("HH:mm") + +FIELDS["short-time"] = proc():string = + return $NOW.format("HH:mm tt") + +FIELDS["time-24"] = proc():string = + return $NOW.format("HH:mm:ss") + +FIELDS["time"] = proc():string = + return $NOW.format("HH:mm:ss tt") + + + +FIELDS["day"] = proc():string = + return $NOW.format("dd") + +FIELDS["month"] = proc():string = + return $NOW.format("MM") + +FIELDS["year"] = proc():string = + return $NOW.format("yyyy") + +FIELDS["short-day"] = proc():string = + return $NOW.format("d") + +FIELDS["short-month"] = proc():string = + return $NOW.format("M") + +FIELDS["short-year"] = proc():string = + return $NOW.format("yy") + + + +FIELDS["weekday"] = proc():string = + return $NOW.format("dddd") + +FIELDS["weekday-abbr"] = proc():string = + return $NOW.format("dd") + + + +FIELDS["month-name"] = proc():string = + return $NOW.format("MMMM") + +FIELDS["month-name-abbr"] = proc():string = + return $NOW.format("MMM") + + + +FIELDS["timezone-offset"] = proc():string = + return $NOW.format("zzz") + +FIELDS["timezone"] = proc():string = + return $NOW.format("ZZZ") + + # Procedures

@@ -70,7 +159,7 @@ return false

try: timeinfo = TimeInfo(year: parts[0], month: Month(parts[1]-1), monthday: parts[2]) # Fix invalid dates (e.g. Feb 31st -> Mar 3rd) - timeinfo = getLocalTime(timeinfo.timeInfoToTime); + timeinfo = getLocalTime(timeinfo.toTime); return true except: return false

@@ -155,6 +244,24 @@

proc embed_fonts*(): string= return style_tag(fonts.join); + +# Field Usage: +# {{$timestamp}} + +proc parse_fields*(document: string): string = + NOW = getTime().getLocalTime() + var doc = document + for field in document.findAll(peg_field): + var matches:array[0..0, string] + discard field.match(peg_field, matches) + var id = matches[0].strip + if FIELDS.hasKey(id): + doc = doc.replace(field, FIELDS[id]()) + else: + stderr.writeLine "Warning: Field '" & id & "' not defined." + doc = doc.replace(field, "") + return doc + # Snippet Definition: # {{test -> My test snippet}} #

@@ -194,7 +301,8 @@ output_file = inputsplit.dir/inputsplit.name & ".htm"

var source = input_file.readFile - # Parse snippets + # Parse fields and snippets + source = parse_fields(source) source = parse_snippets(source) # Document Variables

@@ -226,6 +334,9 @@ toc = ""

if user_css != nil: user_css_tag = user_css.readFile.style_tag + + + # Date parsing and validation var timeinfo: TimeInfo = getLocalTime(getTime())
M hastyscribe.nimblehastyscribe.nimble

@@ -1,6 +1,6 @@

[Package] name = "hastyscribe" -version = "1.1.4" +version = "1.2.0" author = "Fabio Cevasco" description = "Self-contained markdown compiler generating self-contained HTML documents" license = "MIT"

@@ -44,4 +44,4 @@ vendor/libmarkdown_linux_arm.a

""" [Deps] -Requires: "nimrod >= 0.12.0" +Requires: "nimrod >= 0.14.0"