tags:

views:

561

answers:

5

I'm writing some documentation in Markdown, and creating a separate file for each section of the doc. I would like to be able to convert all the files to HTML in one go, but I can't find anyone else who has tried the same thing. I'm on a Mac, so I would think a simple bash script should be able to handle it, but I've never done anything in bash and haven't had any luck. It seems like it should be simple to write something so I could just run:

markdown-batch ./*.markdown

Any ideas?

+1  A: 

I use this in a .bat file:

@echo off
for %i in (*.txt) python markdown.py "%i"
Julio César
A: 

Why not take an existing Markdown parser, such as Gruber's (PERL) or one of the Ruby versions, and apply it to each file in the directory of files you want to convert, and then just create a new file with the converted text? If you're looking for an actual solution, I can write one in Ruby and post it when I'm done.

Brian Warshaw
+5  A: 

This is how you would do it in Bash.

for i in ./*.markdown.txt; do perl markdown.pl --html4tags $i > $i.html; done;

Of course, you need the Markdown script.

Edit: Added "> $i.html" which Brock himself pointed out was necessary.

Patrick McElhaney
+5  A: 

Use pandoc It's a commandline tool that lets you convert from one format to another. This tool supports Markdown to html and back.

+1 for pandoc... since he's writing it in sections, use pandoc to concatenate the necessary sections into one html file, if necessary.
Mica
+1  A: 

Thanks, Patrick! I added just a little to save the output into HTML files:

for i in ./*.markdown.txt; do perl markdown.pl --html4tags $i > $i.html; done;
Brock Boland