Posts tagged with 'markdown'

Implementing MarkDown for comments

I haven’t been too happy about the facilities for commenting in GraffitiCMS ever since I started using it. Great for minor feedback, but awful for pasting code when crafting an implementation detail as an example. Since StackOverflow uses MarkDown for its comments and I’ve grown used to that, I decided to experiment adding it to my blog here as well.

filenes_0011photo © 2006 David Boyle | more info (via: Wylio)

Problem number 1: finding a JavaScript implementation of a MarkDown parser. As Jeff Atwood found out: the archetypal implementation is by John Fraser of AttackLabs who, basically, has fallen off the face of the Earth. In fact, the AttackLabs web site is no longer active and is generically parked. Not to worry: the code is still available. It turns out it’s called showdown.js and you can get it here.

(It’s hosted elsewhere as well, by the way. It seems that several people have copied it into various software repositories.)

Problem number 2: GraffitiCMS modifies the text of a comment when you save it. The first is to encode the text so that entities like left angle bracket are converted to &lt; and so on. The rest of the modifications are pretty benign — essentially converting paragraphs by surrounding them with <p></p> tags — so I wrote a small bit of JavaScript on the client to remove those tags and then convert the result from MarkDown to HTML.

That seemed like the simplest way out since I didn’t want to pre-process all the comments I already have in the database. Although this solution may be the easiest, it is a bit of a hack to be sure. Then again, I don’t particularly want to change the GraffitiCMS code either – I did that before and ran into issues when I wanted to refresh from the latest code from the GraffitiCMS project on CodePlex. I may be revisiting this decision later but for now I’m winging it.

Problem number 3: providing a preview panel so that you can see what your comment will look like before you submit it. Well, OK, that wasn’t really a problem: it just amounted to modifying the page templates and writing a bit more CSS and JavaScript. Cool.

So, there you have it. Rich text comments using MarkDown on the boyet blog.

Album cover for The Richest Man in BabylonNow playing:
Thievery Corporation - Un Simple Histoire (A Simple History)
(from The Richest Man in Babylon)


Extras

Search

About Me

I'm Julian M Bucknall, the M because it's my middle initial and because I and the other Julian Bucknall (the movie guy) would like to differentiate ourselves.

I'm a programmer by trade, an actor by ambition, and an algorithms guy by osmosis. I write articles for PCPlus in my spare time, not that there's much of that.

Julian M Bucknall Apart from that, an ex-pat Brit, atheist, microbrew enthusiast, Pet Shop Boys fanboy, slide rule and HP calculator collector, amateur photographer, Altoids muncher.

DevExpress

I'm Chief Technology Officer at Developer Express, a software company that writes some great controls and tools for .NET and Delphi. I'm responsible for the technology oversight and vision of the company.

Validation

Validate markup as HTML5 (beta)     Validate CSS

Bottom swirl

Archives

May 2012 (4)
SMTWTFS
« Apr  
12345
6789101112
13141516171819
20212223242526
2728293031

Like this Archive Calendar widget? Download it here.

Social networking

The OUT Campaign

The OUT Campaign

My Tweets

  • Honest Movie Trailer of Phantom Menace http://t.co/sif8y4Ns and then Battleship, er, Transformers http://t.co/sif8y4Ns
  • Damn, Donna Summer and Chuck Brown both gone in the last 24 hours. Different types of music, sure, but enjoyed them both. :(
  • Just saw a company page showing a list of tweets with "Join the conversation" linked to their Twitter a/c. The tweets are 6 months old #fail
Bottom swirl