Templating¶
A basic mdtmpl
instruction looks like this:
mdtmpl
parses the template file and all its markdown comments and renders its instructions. It uses the Go`s Template Engine.
Follow this document to see which template functions are supported.
Piping¶
You can pipe the output of one instruction to the next template function as its last argument:
For example: <!--- {{ "hello!" | upper | repeat 5 }} --->
will result in:
HELLO!HELLO!HELLO!HELLO!HELLO!
.
Template Functions¶
mdtmpl
includes all sprout
and Go`s predefined template functions.
Furthermore, the following functions are also available:
code "<language>" "<content>"
¶
Syntax highlight a given content in a specified language within a code block.
exec "<command>"
¶
Executes a given command and returns the output and an error (if any)
Tip
truncate
removes any trailing empty lines. Useful after exec
hook "<command>"
¶
Executes a given command and returns an error (if any)
Tip
hook
is useful for setting things up or commands that produce some resources, such as images that you want to include.
file "<path>"
¶
Includes the content of the given file
fileHTTP "<url>"
¶
Includes the content of the given url
filesInDir "<dir>" "<glob-pattern">
¶
Returns the paths of all matching files in the specified directory
tmpl "<template-file>"
¶
Includes the rendered content of the given template
tmplWithVars "<template-file>" <values>
¶
Renders a given template with the specified template values
stripansi "<content>"
¶
Strips any Color Codes from a given content
Tip
Useful when a command outputs colored output
collapsile "summary" "<content>"
¶
Creates a collapsible section wit the given summary and content.
toc
¶
Inserts a Markdown Table of Content
Note
For now it does not work for any headings that are included after toc
function invocation. For example when using file
or tmpl
/tmplWithVars