lua-filters
lua-filters copied to clipboard
Filter for variable replacement in code blocks
- Replacing of
${namespace:var}in code blocks with values from the environment or from the meta data block. This is very useful in conjunction with theinclude-files.luafilter. :-)
codeblock-var-replace
Filter to replace variables in code blocks with values from environment
or meta data. All variables in the form ${namespace:name} in a code
block with a class .var-replace are replaced.
Variables
A variables needs to be of the form ${namespace:name} where
namespace is currently one of env,meta with the following replacement behavior:
env: Substituting the environment variablename.meta: Substituting the stringified variablenamefrom the meta data block.
Example
Note that meta data is parsed as markdown, therefore use a
general code blocks `text`:
---
author: "`The fearful bear`"
title: Thesis
monkey: "`Hello: I am a monkey`"
"giraffe and zebra" : "`cool and humble !`"
mypath: "`chapters: 1/A B.txt`"
food: "chocolate"
---
## Replace
``` {.var-replace}
${meta:monkey} and ${env:BANANA}
Zebras and giraffes are ${meta:giraffe and zebra}
${meta:author} thanks for everything in '${meta:mypath}'
and of course eat some ${meta:food}
```
Made the changes, ready to merge. Thanks
Please merge this if possible...