Markdown Toolbox Logo Markdown Toolbox
Home
Blog

Buy Me A Coffee

Using Variables in Markdown Files

Wednesday, November 15, 2023

Short version

Markdown itself does not support variables directly. Use pre-processors like Jekyll, Pandoc, or Markdown Preprocessor (MPP) for variable support.

Long version

Introduction

Variables in documents can greatly enhance the flexibility and reuse of the content. However, Markdown's simplicity means it doesn't natively support variables.

Solution

To use variables in Markdown, you'll typically employ a pre-processor or a static site generator that supports Markdown.

---
name: John Doe
---
Hello, my name is {{ name }}.
pandoc --variable=author:"John Doe" -o output.docx input.md

Conclusion

While Markdown doesn't directly support variables, using tools like Jekyll or Pandoc allows you to add dynamic content to your Markdown documents. This approach leverages the simplicity of Markdown while adding the flexibility of variables.