Skip to content

Filter for variable replacement in code blocks #139

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gabyx
Copy link

@gabyx gabyx commented Nov 11, 2020

  • 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 gabyx force-pushed the feature/codeblock-env-and-meta-replace branch 6 times, most recently from ad230ce to fc59d82 Compare November 12, 2020 22:02
Copy link
Contributor

@lmunch lmunch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List is included without being used. Otherwise it looks good.

@gabyx gabyx force-pushed the feature/codeblock-env-and-meta-replace branch from fc59d82 to 6bd93fd Compare May 9, 2021 18:49
@gabyx
Copy link
Author

gabyx commented May 9, 2021

Made the changes, ready to merge. Thanks

@gabyx gabyx force-pushed the feature/codeblock-env-and-meta-replace branch from 6bd93fd to 19b7839 Compare May 9, 2021 18:53
@gabyx
Copy link
Author

gabyx commented May 21, 2021

Please merge this if possible...

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants