skip to Main Content

Let’s say we have input.md file:

# Name

Contents

— and we need to automatically rewrite it in HTML:

# pandoc --from markdown --to html input.md -o output.html
# cat ./output.html
<h1 id="name">Name</h1>
<p>Contents</p>

Now, we want Pandoc to prepend something like <head><title>Custom title</title></head> to output.html.

How to accomplish this?

The following approaches failed:

# pandoc --from markdown --to html --metadata title="Custom title" input.md -o output.html

# echo '{title: "Custom title"}' > metadata.json
# pandoc --from markdown --to html --metadata-file=metadata.json input.md -o output.html

Also, I am aware of --title command line option: it indeed creates <title> in my case, but writes Custom title – input there, and also adds a lot of styles (although the latter is not an issue itself).

2

Answers


  1. Chosen as BEST ANSWER

    Finally, a command line snippet solving my issue follows (great thanks to @mb21 for the answer and the comment above):

    # pandoc -s -V pagetitle="Custom title" input.md -o output.html
    

  2. You’re missing the -s or --standalone option:

    pandoc -s --metadata title="Custom title" input.md -o output.html
    

    Or instead of the --metadata flag just do:

    ---
    title: Custom title
    ---
    
    Contents
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search