lunamark.util
Utility functions for lunamark.
find_template(name)
Find a template and return its contents (or false if not found). The template is sought first in the working directory, then in templates, then in $HOME/.lunamark/templates, then in the Windows APPDATA directory.
sepby(arg)
Implements a sepby directive for cosmo templates. $sepby{ myarray }[[$it]][[, ]] will render the elements of myarray separated by commas. If myarray is a string, it will be treated as an array with one element. If it is nil, it will be treated as an empty array.
err(msg, exit_code)
Print error message and exit.
table_copy(t)
Shallow table copy including metatables.
expand_tabs_in_line(s, tabstop)
Expand tabs in a line of text. s is assumed to be a single line of text. From Programming Lua.
walk(t, f)
Walk a rope t, applying a function f to each leaf element in order. A rope is an array whose elements may be ropes, strings, numbers, or functions. If a leaf element is a function, call it and get the return value before proceeding.
flatten(ary)
Flatten an array ary.
rope_to_string(rope)
Convert a rope to a string.
rope_last(rope)
Return the last item in a rope.
intersperse(ary, x)
Given an array ary, return a new array with x interspersed between elements of ary.
map(ary, f)
Given an array ary, return a new array with each element x of ary replaced by f(x).
escaper(char_escapes, string_escapes)
Given a table char_escapes mapping escapable characters onto their escaped versions and optionally string_escapes mapping escapable strings (or multibyte UTF-8 characters) onto their escaped versions, returns a function that escapes a string. This function uses lpeg and is faster than gsub.