mrosales
mrosales

Reputation: 1568

Pandoc - Insert separator between files

I am trying to use pandoc to merge a bunch of markdown files into a single html document. Each file is for a different class lecture, and my goal is to have a <hr> tag inserted between each markdown file, so it is easier to see where the lecture breaks occur.

I know it is possible to add the breaks manually, or style the html such that each new header tag also has a rule, but I would like to learn how to do this with just pandoc.

My current command looks like:

pandoc *.md > output.html

I have tried using the -A flag, but that inserts something after the ENTIRE body, whereas I want to insert a rule between each markdown document.

I realize that this may not be possible (if pandoc concatenates before processing), and in that case, I can just preprocess/concat the files with another script.

To summarize, I want a way to do

[01.md]
<hr>
[02.md]
<hr>
...
[last.md]

Upvotes: 2

Views: 1307

Answers (1)

mrosales
mrosales

Reputation: 1568

This is not exactly what I was hoping for, but I realized I can use gnu-sed to just add the separators to the markdown document before concatenating to make pandoc insert the <hr> tags.

The extra newlines are to make sure the separator is on its own line and the md file ends with a newline so pandoc works properly

sed -s '$a\\n----\n' *.md | pandoc -f markdown > output.html

Solution from a previous superuser answer

Note: for OSX you need to do brew install gnu-sed and use gsed instead of sed

Upvotes: 1

Related Questions