[Solved] It is possible to have conditionnal block in a separate yaml metadata file ? #11763
|
Hi there, I read here that Pandoc supports a separate YAML metadata file with conditional options like this: ---
title: "Some Title"
subtitle: "Markdown est vraiment formidable"
author:
- Jane Doe
date: "2026-07-10"
---
# HTML settings
---
if: format == "html"
language: "fr-FR"
number-sections: true
number-offset: 0
toc: true
toc-depth: 3
---
# PDF settings
---
if: format == "pdf"
header-includes: |
\usepackage[default]{sourcesanspro}
\usepackage[T1]{fontenc}
number-sections: true
number-offset: 0
toc: true
toc-depth: 3
mainfont: "Calibri"
classoption: "a4paper"
geometry: margin=2cm
colorlinks: true
---
# EPUB settings
---
if: format == "epub"
number-sections: true
number-offset: 0
---This is my metadata file, and here are the pandoc options for html index file: pandoc ./sources/*.md \
--from="markdown+smart" \
--to=html \
--output="./_build/html/index.html" \
--standalone=true \
--template="./templates/html/elegant_bootstrap_menu.html" \
--metadata-file="./metadata.yml"but it does not work as expected. The HTML conditional block is not considered. Best regards, |
Replies: 3 comments 7 replies
|
This business with conditionals ( Perhaps some other tool that wraps pandoc allows this. But the site you link to has the air of AI generated slop. |
|
I think it's the second |
|
Defaults files specify command-line options, so to set metadata you need to add a |
Note that it is definitely possible to conditionally inject things into metadata depending on the format, but you'd have to use a Lua filter to do that.
It would even be possible to write a general filter that allowed you to do something like this:
Please refer to the pandoc manual and the manual on Lua filters for reliable documentation.