Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Technical authors are increasingly being encouraged to write in standalone topics.

Topics are written so that they make sense when compiled into different packages or when they are read in isolation.

There are heavily-engineered structured formats for topic-based writing but I want to use Pandoc and Markdown.

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 will need compile a list of selected Markdown files and process that to achieve a topic-based workflow.

If I have some Markdown files:

inputfile1.md, inputfile2.md, inputfile3.md

what is a simple shell script that I can use that can compile them and process them using Pandoc to a single output file?

share|improve this question
2  
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? –  Hauke Laging May 27 '13 at 1:27

2 Answers 2

up vote 5 down vote accepted

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
share|improve this answer

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.