PanDoc: How to assign level-one Atx-style header (markdown) to the contents of html title tag -


i using pandoc convert large number of markdown (.md) files html. i'm using following windows command-line:

for %%i in (*.md) pandoc -f markdown -s %%~ni.md > html/%%~ni.html 

on test run, html looks ok, except title tag - it's empty. here example of beginning of .md file:

#topic title - [anchor 1](#anchor1) - [anchor 2](#anchor2) <a name="anchor1"></a> ## anchor 1 

is there way can tell pandoc parse the

#topic title 

so that, in html output files, get:

<title>topic title</title> 

?

there other .md tags i'd parse, , think solving me solve rest of it.

i don't believe pandoc supports out-of-the-box. relevant part of pandoc documentation states:

templates may contain variables. variable names sequences of alphanumerics, -, , _, starting letter. variable name surrounded $ signs replaced value. example, string $title$ in

<title>$title$</title> 

will replaced document title.

it continues:

some variables set automatically pandoc. these vary depending on output format, include metadata fields (such title, author, , date) following:

and proceeds list bunch of variables (none of relevant question). however, above quote indicates title variable metadata field. metadata field can defined in pandoc_title_block, yaml_metadata_block, or passed in command line option.

the docs note that:

... may keep metadata in separate yaml file , pass pandoc argument, along markdown files ...

so have couple options:

  1. edit each document add metadata defining title each document (this possibly scripted).
  2. write script extract title (perhaps regex looks #header in first line) , passes in pandoc command line option.

if intend start including metadata in new documents create going forward, first option way go. run script once batch edit documents , done. however, if have no intention of adding metadata documents, consider second option. running loop, title before calling pandoc within loop (although i'm not sure how in windows script).


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -