Replies: 4 comments 1 reply
-
- Please add yaml fields into usable variables.
---
title: "my title"
---
# $title$
I want to discuss the $title$.
For the moment, this can be done using a filter like the following one:
```
local placeholders = {}
local function get_placeholder_data(meta)
for placeholder, value in pairs(meta.placeholders) do
placeholders[placeholder] = value
end
end
local function replace_placeholders(str)
local value
local before, placeholder, after = string.match(str.text, '(.*){{([^}]+)}}(.*)')
if placeholder then
value = placeholders[placeholder]
if value then
if before then table.insert(value, 1, pandoc.Str(before)) end
if after then table.insert(value, pandoc.Str(after)) end
else
value = pandoc.Strong(pandoc.Str('??'))
warn('Definition not found for the placeholder "' ..
placeholder .. '".')
end
end
return value
end
return {
{ Meta = get_placeholder_data },
{ Str = replace_placeholders }
}
```
Here is a sample:
```
---
title: "my title"
placeholders:
title: "my title"
myname: "John [Doe]{.smallcaps}"
---
# {{title}}
I, {{myname}}, want to discuss the {{title}}.
```
Note that the dollars syntax is to be avoided here for it is already used by the tex_math_dollars extension.
|
Beta Was this translation helpful? Give feedback.
-
this would be a very nice feature for everyone to have. most importantly, the implementation and maintenance cost for this feature on the pandoc end would probably be modest. |
Beta Was this translation helpful? Give feedback.
-
See https://pandoc.org/MANUAL.html#variables-set-automatically -- specifically |
Beta Was this translation helpful? Give feedback.
-
add |
Beta Was this translation helpful? Give feedback.
-
Please add the current filename into a variable that the template can use (default templates loading accompanying style files #9974). Effort should be minimal --- on file opening, just populate the global variable. (It could be more elegant if it were a list that was pushed and popped, but I don't know Haskell.). Ideally, have the basename as a global, too. Having these variables makes for much more elegant templates that use the filename to include related files.
<link rel="stylesheet" href="$basename.css">
.Please add yaml fields into usable variables.
The relative effort of offering this feature (if it doesn't already exist and I missed it) inside pandoc itself vs. writing a preprocessor that rescans the YAML is probably low.
Beta Was this translation helpful? Give feedback.
All reactions