all repos — hastyscribe @ 96364b721635e139a8078acfa69eac4aa08c2813

A professional markdown compiler.

Don't use proc: in HastyFields table
It was not gcsafe and compilation failed when HastyStyle was called from LiteStore
kaminski kaminski@naew.nato.int
Tue, 30 Mar 2021 22:21:20 +0200
commit

96364b721635e139a8078acfa69eac4aa08c2813

parent

8ac9afc750354133311c4020209f8c377187e073

1 files changed, 31 insertions(+), 49 deletions(-)

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

@@ -49,7 +49,7 @@ css*: string

js*: string watermark*: string fragment*: bool - HastyFields* = Table[string, proc():string] + HastyFields* = Table[string, string] HastySnippets* = Table[string, string] HastyMacros* = Table[string, string] HastyScribe* = object

@@ -63,52 +63,31 @@ if logging.getHandlers().len == 0:

newNiftyLogger().addHandler() proc initFields(fields: HastyFields): HastyFields {.gcsafe.} = - result = initTable[string, proc():string]() + result = initTable[string, string]() for key, value in fields.pairs: result[key] = value var now = getTime().local() - result["timestamp"] = proc():string = - return $now.toTime.toUnix().int - result["date"] = proc():string = - return now.format("yyyy-MM-dd") - result["full-date"] = proc():string = - return now.format("dddd, MMMM d, yyyy") - result["long-date"] = proc():string = - return now.format("MMMM d, yyyy") - result["medium-date"] = proc():string = - return now.format("MMM d, yyyy") - result["short-date"] = proc():string = - return now.format("M/d/yy") - result["short-time-24"] = proc():string = - return now.format("HH:mm") - result["short-time"] = proc():string = - return now.format("HH:mm tt") - result["time-24"] = proc():string = - return now.format("HH:mm:ss") - result["time"] = proc():string = - return now.format("HH:mm:ss tt") - result["day"] = proc():string = - return now.format("dd") - result["month"] = proc():string = - return now.format("MM") - result["year"] = proc():string = - return now.format("yyyy") - result["short-day"] = proc():string = - return now.format("d") - result["short-month"] = proc():string = - return now.format("M") - result["short-year"] = proc():string = - return now.format("yy") - result["weekday"] = proc():string = - return now.format("dddd") - result["weekday-abbr"] = proc():string = - return now.format("dd") - result["month-name"] = proc():string = - return now.format("MMMM") - result["month-name-abbr"] = proc():string = - return now.format("MMM") - result["timezone-offset"] = proc():string = - return now.format("zzz") + result["timestamp"] = $now.toTime.toUnix().int + result["date"] = now.format("yyyy-MM-dd") + result["full-date"] = now.format("dddd, MMMM d, yyyy") + result["long-date"] = now.format("MMMM d, yyyy") + result["medium-date"] = now.format("MMM d, yyyy") + result["short-date"] = now.format("M/d/yy") + result["short-time-24"] = now.format("HH:mm") + result["short-time"] = now.format("HH:mm tt") + result["time-24"] = now.format("HH:mm:ss") + result["time"] = now.format("HH:mm:ss tt") + result["day"] = now.format("dd") + result["month"] = now.format("MM") + result["year"] = now.format("yyyy") + result["short-day"] = now.format("d") + result["short-month"] = now.format("M") + result["short-year"] = now.format("yy") + result["weekday"] = now.format("dddd") + result["weekday-abbr"] = now.format("dd") + result["month-name"] = now.format("MMMM") + result["month-name-abbr"] = now.format("MMM") + result["timezone-offset"] = now.format("zzz") proc newHastyScribe*(options: HastyOptions, fields: HastyFields): HastyScribe = return HastyScribe(options: options, fields: initFields(fields), snippets: initTable[string, string](), macros: initTable[string, string](), document: "")

@@ -281,7 +260,7 @@ var matches:array[0..0, string]

discard field.match(peg_field, matches) var id = matches[0].strip if hs.fields.hasKey(id): - result = result.replace(field, hs.fields[id]()) + result = result.replace(field, hs.fields[id]) else: warn "Field '" & id & "' not defined." result = result.replace(field, "")

@@ -509,13 +488,14 @@ (Use "--output-file=-" to output to stdout)

--watermark=<file> Use the image in <file> as a watermark. --fragment If specified, an HTML fragment will be generated, without embedding images, fonts, or stylesheets. - --dump=all|styles|fonts Dumps all resources/stylesheets/fonts to the current directory.""" + --dump=all|styles|fonts Dumps all resources/stylesheets/fonts to the current directory. + --help Display the usage information.""" var input = "" var files = newSeq[string](0) var options = HastyOptions(toc: true, output: "", css: "", watermark: "", fragment: false) - var fields = initTable[string, proc():string]() + var fields = initTable[string, string]() var dumpdata = "" # Parse Parameters

@@ -543,11 +523,13 @@ of "output-file":

options.output = val of "fragment": options.fragment = true + of "help": + echo usage + quit(1) else: if key.startsWith("field/"): let val = val - fields[key.replace("field/", "")] = proc(): string = - return val + fields[key.replace("field/", "")] = val discard else: discard