As simple as possible, as complex as necessary

Including code in Disqus comments

25 September 2012

Since this blog is "baked" into a static website each time I post, it can't have an "in-house", dynamically generated commenting system.

Instead I use Disqus which allows me to offer the functionality via Javascript.

Not only is my blogging set-up simpler for not having to support commenting "natively", I've also found Disqus does a pretty good job at minimising spam and reducing the general maintenance burden.

From the viewpoint of someone posting comments, however, there is at least one downside: it's not great when it comes to including code samples.

As I'm not the only ColdFusion blogger using Disqus (see Adam Cameron's excellent new blog for instance), here are some tips should you wish to illustrate your Disqus comments with CF or other code snippets:

  1. Enclose your code samples within <pre><code> tags. Not only will the font change to present the code more clearly, Disqus will also attempt to apply syntax highlighting/colouring. You can help the parser by specifying the language as a class attribute to the code tag, e.g. <code class="html">. Predictably I suppose, the list of languages Disqus's syntax parser supports doesn't include CFML.
  2. Watch out for self- or non-closing tags, such as <cfargument> and <cfreturn> (adding a trailing slash—<cfargument/>—makes no difference). Currently Disqus's parser will insist on inserting closing tags for these in silly places, resulting in mangled code. The only way I've found to stop the automatic insertions is to close the tags explicitly yourself: <cfreturn></cfreturn>. Not great, but at least you control where the tags are closed.
  3. Use cfscript if possible: given the above, it's a lot safer.

A limited set of other HTML tags are allowed for general formatting in Disqus comments.

UPDATE 2 February 2013 It seems that the Disqus syntax support is even worse than I thought. If you include any of the allowed HTML tags, they will not be escaped.

And as one commenter below has discovered, even PHP is not properly supported, despite being on the supported language list.

I've reported these issues to Disqus who have replied acknowledging the HTML conflict, adding:

We are looking into implementing a Markdown-style code that could do the formatting for you, but it may take some time to implement.


  • Formatting comments: See this list of formatting tags you can use in your comments.
  • Want to paste code? Enclose within <pre><code> tags for syntax higlighting and better formatting and if possible use script. If your code includes "self-closing" tags, such as <cfargument>, you must add an explicit closing tag, otherwise it is likely to be mangled by the Disqus parser.
Back to the top