7

Processing a single Markdown file to HTML:

pandoc -f markdown -t html inputfile.md

Although I can use Pandoc like this to process individual Markdown files, I want to compile a list of selected Markdown files and process them to a single file.

If I have some Markdown files:

inputfile1.md, inputfile2.md, inputfile3.md

How can I compile them and process them using Pandoc to a single output file?

1
  • 3
    You give ten lines of irrelevant background information and ask a one line question which is missing all necessary information. Usually an example is given if people have such problems. How are the files selected and how shall the shell process them? May 27, 2013 at 1:27

2 Answers 2

9

pandoc can take multiple input files. Just use:

pandoc -s -o output.html input1.md input2.md input3.md

-s tells pandoc to create a self-contained file (so it will contain <html></html> tags etc, rather than just generating a fragment). -o output.html specifies that output.html will be the output file. With the output file ending in .html, -t html is unnecessary - if you want to output to STDOUT, obviously keep it.

After a little bit of testing, it seems that -f markdown isn't necessary even when using inputs without a file extension - either because it's the default markup that pandoc expects, or pandoc can detect what markup language is being used.

You can, of course, use globs in order to type less:

pandoc -s -o output.html input*.md
9

You give a lot of background, but it's hard to tell what you actually want on a functional level, so I'm mostly guessing about how your files are structured here. In future, please provide less background and more information that is relevant to the question so that you can be helped more efficiently.

If you want to compile all *.md files in the current directory into their own files:

for file in *.md; do
    pandoc -f markdown -t html "$file"
done

If you want to compile all *.md files in the current directory into their own files, recursively:

find . -name '*.md' -exec pandoc -f markdown -t html {} \;

If you want to compile all *.md files in the current directory into one file:

pandoc -f markdown -t html -o foo.html *.md 

If you want to compile all *.md files in the current directory into one file, recursively (not POSIX):

pandoc -f markdown -t html <(find . -name '*.md' -exec cat {} +) -o foo.html

Or (bash4+):

shopt -s globstar
pandoc -f markdown -t html -o foo.html **/*.md

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .