Random Notes

Adding a width option to pandoc-bash-blog

2025-04-12

Giving each post a width option in the yaml metadata to select between narrow for single-column English to wide for two-column translation posts.

  1. Save Pandoc’s default template

    pandoc --print-default-template=html5 > custom-template.html
  2. Make one single change in custom-template.html:

    - <body>
    + <body class="$if(width)$$width$$else$narrow-width$endif$">
  3. Update your md2html function to use this template:

    md2html() {
        local args=(
            # ... your existing args ...
            "--template=custom-template.html"  # Add this line
        )
        # ... rest of your function ...
    }
  4. Usage in markdown files:

    ---
    title: My Post
    width: wide-width  # narrow-width (default) | medium-width | wide-width | full-width
    ---

Key Benefits:

Maintenance

Keep your custom-template.html under version control so it stays with your project. If you ever need to update it (e.g., when upgrading Pandoc), just regenerate it and reapply your single-line change.