diff options
author | Martin Fischer <martin@push-f.com> | 2022-10-28 08:58:12 +0200 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2022-10-28 12:05:09 +0200 |
commit | 0b699948d33c6b209439e2eb77c60c220130dc6b (patch) | |
tree | 9a042f9c787d4e5854869c31db22644fa040f380 /README.md | |
parent | d2b0892241d9a5bbdf6b701cc7c8c182c9a6c727 (diff) |
implement lua-based templates
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 33 |
1 files changed, 32 insertions, 1 deletions
@@ -80,7 +80,38 @@ name = "John Doe" email = "john@example.com" ``` -## Lua scripting +## Lua templates + +You can define Lua functions in `.lua` files within the `modules/` directory +and then call them within `.md` files using the `{{modulename.functionname}}` +syntax. For example if you create `modules/example.lua` with: + +```lua +function greet(args) + return 'Hello ' .. args[1] .. '!' +end + +function sum(args) + return args.x + args.y +end + +return {greet=greet, sum=sum} +``` + +within Markdown files `{{example.greet|world}}` will become +`Hello world!` and `{{example.sum|x=3|y=5}}` will become 8. + +Note that: + +* If no module name is given it defaults to `default` so e.g. `{{foo}}` + will attempt to call the `foo` function defined in `modules/default.lua`. +* In order to pass `|` or `}}` within arguments you need to + escape them by prefixing a slash e.g. `{{foo| \| \}} }}`. +* Within `<pre>` and `<raw>` tags and HTML comments no special syntax is interpreted. +* Note that none of these constructs can be nested. E.g. `{{foo|{{bar}} }}` or + `{{foo|<raw>test</raw>}}` will not work as you might expect. + +## Lua shebangs Files can start with a shebang like `#!hello`, which will interpret the following text with the `view` function returned |