Markdown to web-publishing workflow
January 31, 2009 3:56 PM   Subscribe

Info-management filter: Is there a software/script that will take my several directories full of Markdown-formatted txt files and publish them into html pages?

I have a bunch of text files strewn across my computer along with other types of files. All of them are in Markdown format. Is there any script or publishing system that can recursively look at all my text files and generate html files from them.

Basically, I need to keep a lot of textual information and the best way I have found for that is using text files on my computer since I don't like web-interfaces for editing and stuff. But man! do I miss a publishing system. I did try locally-installed wikis but either they were too cumbersome or I couldn't bring myself to use the textareas for content entry.

I am on a Mac btw (Leopard).
posted by raheel to Computers & Internet (7 answers total)
 
If you know ho to use git, svn or another vcs, ikiwiki has a textual interface. Set it up, clone the repo, then add and commit your files with the mdwn extension. A commit hook will run and generate html.
posted by Tobu at 4:05 PM on January 31, 2009


This discussion seems to present a nice one-liner for using the markdown script in the terminal to convert a directory of markdown files to html. Although it doesn't drill down through directories, it'd be a starting point.

This page (google cache) details a simple CMS much like you're looking for, which just parses markdown files and presents them as HTML, but their site's down at the moment.
posted by closetpacifist at 4:14 PM on January 31, 2009


Did you look at the Markdown homepage? Markdown is written in the Perl scripting language. Perl is already installed on your Mac. The command line example to convert one file from Markdown to HTML is:
perl Markdown.pl --html4tags foo.text
It should be fairly easy to write a Perl or shell script to do that recursively to each file under a certain directory. I don't have time to write it at the moment, but someone on the Markdown mailing list might take pity on you. You might even be able to do it using Automator. Good luck.
posted by paulg at 7:23 PM on January 31, 2009


Walking a directory recursively is actually surprisingly nontrivial to do in shell scripts. Since you have Leopard I think you have Python, which makes this much easier. You could, for example, run something like this!

(Perl also works, but I have a strong personal distaste for the Perl equivalent of os.walk, which is File::Find.)
posted by shadytrees at 8:04 PM on January 31, 2009


If you just want to call an executable on a list of files under a directory with a certain name pattern, do that:
find dir -type f -name '*.mdwn' -print0 |xargs -0 markdown

Replace markdown with perl Markdown.pl or whatever your conversion command is.
posted by Tobu at 2:08 AM on February 1, 2009


Response by poster: Thanks everyone. I'm working on a customized script to translate mkdwn > html in a mirrored directory structure.
posted by raheel at 1:01 PM on February 1, 2009


Just to comment to shadytrees and his understandable dislike of File::Find -- you should check out File::Find::Rule. It's what the kids are using nowadays.
posted by AmbroseChapel at 8:56 PM on February 1, 2009


« Older A short trip to D.C.   |   Help me pick a latex mattress! Newer »
This thread is closed to new comments.