Skip to content
This repository has been archived by the owner on Oct 13, 2024. It is now read-only.

Interpolated Variable Processor #95

Open
ghost opened this issue Apr 24, 2020 · 1 comment
Open

Interpolated Variable Processor #95

ghost opened this issue Apr 24, 2020 · 1 comment

Comments

@ghost
Copy link

ghost commented Apr 24, 2020

A while ago I wrote yamlp, a YAML preprocessor that performs string variable interpolation. The app was written because Pandoc does not have a way to perform variable interpolation itself. However, despite having a standalone YAML preprocessor, it makes the tool chain all kinds of awkward (piping Pandoc into itself). I've written up a section on how to use yamlp as part of my series on Typesetting Markdown.

From a higher vantage point, YAML is merely one type of structured document format that can be used for interpolated variables. In theory, any hierarchical data could be used, as shown in the following architecture diagram for Markdown editors:

Text Editor Architecture

It would be spectacular if there was a way to have PP perform the preprocessing of Markdown that includes interpolating and injecting variables from structured data formats. Consider:

pp --var-source=https://api.host.com/v1/records \
  --var-type=yaml --var-delim-start="$" --var-delim-end="$" --var-delim-sep="." \
  filename-in.md > filename-out.md

pandoc -f markdown -t context filename-out.md

Given a YAML source document such as:

a: A 
b: $a$ B 
c: $b$ C $b$
d: $a$ $b$ $c$ D $a$
e:
  f: 
    g: G
h: H and $e.f.g$

If PP's input Markdown document was:

Hello $h$ and $d$.

After running PP, the Markdown document for Pandoc would resemble:

Hello H and G and A A B A B C A B D A.

Various variable name delimiters and internal separator tokens, such as {{ and }} and ., should be configurable as well. This would allow for many variable syntaxes, including R Markdown.

@CDSoft
Copy link
Owner

CDSoft commented Dec 22, 2023

Sorry for the late reply... Please keep in mind that pp is not supported anymore, it's hard to deploy. For new projects I suggest ypp which is is based on a Lua interpreter and way easier to compile and install and binaries are easier to produce (thanks to zig) and deploy (see hey).

This can be done with ypp and some Lua YAML parser. Or even with ypp and Lua tables.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant