lua-filters icon indicating copy to clipboard operation
lua-filters copied to clipboard

Filter for variable replacement in code blocks

Open gabyx opened this issue 5 years ago • 2 comments

  • 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 the include-files.lua filter. :-)

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 variable name.
  • meta : Substituting the stringified variable name from 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}
```

gabyx avatar Nov 11 '20 21:11 gabyx

Made the changes, ready to merge. Thanks

gabyx avatar May 09 '21 18:05 gabyx

Please merge this if possible...

gabyx avatar May 21 '21 19:05 gabyx