Fixing the Comment System, Part 1

I’ve never made a secret of the fact that I don’t like my comment system. I even had a warning on the comment form about how bad my comment system was. No line breaks. No linking. No HTML of any sort… well, except that <p> and <br /> seemed to work, but no one used them. It’s basically the raw writeback plugin for Blosxom. The only enhancements I made were to capture timestamps and IP addresses, and to send myself email notification of new comments. Hardly noticable when trying to read the comments.

I’ve been meaning to do something about it forever. Tonight I finally got started. My main requirements for the new system were:

  • Easy to use
  • Typical feature set: links, bold & italic, code would be nice
  • Maintain valid XHTML, but don’t require the users to understand XHTML.

It was the last feature that really dictated terms to the rest of the crowd. Fortunately, there’s already a fantastic tool for generating valid XHTML easily, with many common features – Markdown. I’ve been using it for a couple of months to author all of my posts, and I love it. Using it for comments seemed like a logical next step.

Markdown only generates valid XHTML, but it passes through any XHTML in the original text unchanged. This would allow any comment to invalidate my XHTML. (It should be noted in the interest of fairness that comment form itsself is not valid XHTML at the moment. It’s on my list.) My solution was to change Markdown to encode all XHTML (and other uses of < and >) entered by the user. In addition, I had to hack a few templates as well as the writeback plugin. So far it’s working pretty well. All comments are now rendered via Markdown. If you see any that look strange, shoot me an email.

One of the best features of Markdown in my mind is that its useful even if you don’t know it, since it borrows from email idioms. Blank lines start new paragraphs. *Emphasis* and **strong emphasis** are easy to do. URLS wrapped in <> become hyperlinks. Code can be wrapped in \backticks`to format it and escape any nasties. Blockquotes work like email, just prepend>` to each line.

Of course, there’s lots of other features that it helps to know something about ahead of time, such as code blocks and referntial URLs. Plus, occasional surprises can occur; writing about the interpolate_fancy plugin requires a backslash before the underscore if you don’t use backticks, or you invoke <em> mode. For this reason, I’m going to add a mandatory preview prior to posting. I’ll also add some Markdown tips to the comment form. Preview isn’t ready yet, but Markdown-enabled comments are.

Both comments and pings are currently closed.

2 Responses to “Fixing the Comment System, Part 1”

  1. dugh Says:

    out of curiousity…<br/>

    is this something you’re going to be converting to blosxom v.3? it’s definately something i’d be interested in. especially the preview aspect!

  2. Jason Says:

    future plans…<br/>

    Dugh-

    I’m not sure what I’ll be doing with it for now. Right now it’s just a series of hacks in various places. To be honest, I haven’t even figured out how I want to implement the preview.

    One additional problem is that the current system is not quite 100% compatible with standard Blosxom writeback files. Because I currently render the comments via Markdown each time the page is requested, I needed to store the raw markdown text in the comment file (.wb file). Since the standard Blosxom writeback plugin sanitizes comments by encoding things like < and >, attempts to quote HTML in code blocks wouldn't work. Take the following code block:

    
    
    

    I typed it in just as you see it... no < nonsense. Markdown handles it for me. But the standard writeback plugin would normally save the text escaped (<). Currently I've turned off such escaping in the writeback plugin. I also had to hand edit a couple of old comments.

    A better way to handle this would be to let Markdown render the comment before saving it. The problem is it wouldn't address comments already saved on the system. I'm still toying with ways of handling the whole thing.

    If I get it worked out into a coherent system (ha!), I might release it as a plugin. In that event, I'll probably support both Blosxom 2 and 3. I've only played with Blosxom 3 a little, and it's impressive, but I don't know if I'll be switching anytime soon. But that's another post.