The potential of Markdown + Javascript

With the resurgence of Javascript in variety of places - OS X, iOS and my use for it in Maximo, I started to dust off a couple of books to refresh my memory on a few things. As I was going over some stuff on manipulating date/time values and I realized how wonderful this would be in some of the Markdown documents I have. Now the beauty of Markdown is that it's really not just plain text. Yes, the file you saved is just plaintext, but Markdown is a plaintext syntax to format HTML.

Markdown is a text-to-HTML conversion tool for web writers. Markdown allows you to write using an easy-to-read, easy-to-write plain text format, then convert it to structurally valid XHTML (or HTML). 1

So guess what? You can also write straight HTML in a Markdown document. This opens the door to placing simple Javascript straight into your MD files too. The simplest example is using a Javascript to print the current date.

The current date is: .

That sentence was actually written as this in the MD file:

The current date is: <span id="demo"><script>
var d = new Date();
document.getElementById("demo").innerHTML = d.toDateString();
</script></span>.

This article was originally posted on December 16, 2014 13:23:36. So now I can use Javascript within the Markdown file to do some date/time calculations.

Original post date was on and has been up for hours.

As the article sits on the website, the time period will continue to count up.

One more notch in the flexibility column for Markdown.


Update 2014-12-16: In fact the Javascript will even be parsed by some Markdown Editors. In the example below, Byword parsed the entire article properly.


  1. Daring Fireball: Markdown 

Comments

Top