Markdown and XML
I was thinking the other day that it might be nice to create a Markdown to XML program. The idea being that you convert plain text written in Markdown Syntax into an XML file. You can then use XSLT to transform this XML into whatever format you like -> XHTML, LaTeX, OPML, RSS, etc. It might be more straightforward than the approach that I took in MultiMarkdown.
Granted, some of this idea came about because I am interested in learning more about XSLT, and what it could be used for. But I still think it has potential.
I’ve been thinking about this for a while, and then stumbled across this one day:
The main reason I would propose more generic XML rather than XHTML is that it could solve some of the problems currently being discussed regarding footnotes, etc (things for which there is no true XHTML representation.) By using XML you can define these entities, and then your XSLT transformation can convert it to the representation you prefer.
Along these lines, I have created several tools:
xhtml2latex.xslt - the base XSLT file to convert from XHTML to LaTeX. Used by the class-specific files below to handle most of the processing. The output should be valid LaTeX, but will need additional information in order to be converted to something useful (e.g. a \usepackage command, etc). There is also support for SmartyPants markup.
xhtml2memoir.xslt - Convert an XHTML page to LaTeX (specifically the memoir class). Uses the xhtml2latex.xslt file.
xhtml2report.xslt - Same thing, but uses report class. Less features available.
xhtml2article.xslt - And one for the article class.
opml2markdown.xslt - Convert an OPML outline file to Markdown text. The outline items in the OPML are converted to appropriate level headers, and the text of the item (the _note) is placed after the header. You can then run the Markdown text through markdown in order to create a web page, and then optionally through xhtml2latex.xslt to create a LaTeX document.
OmniOutlinerMarkdownPlugin - Export plugin for OmniOutliner that allows you to save an outline as a Markdown text file.
These tools are first drafts, and I am sure they still need some work. Feel free to email/comment with suggestions, or to update the files on the wiki!
How to use these tools
I run xsltproc on Mac OS X 10.4.3. However, the version that is included by apple is outdated. For that reason, I recommend using fink to install a newer version that has several bug fixes applied.
Don’t forget to use the
-nonet options when running xsltproc manually (these options are included in my drag and drop tools.)