pwnt.be

Richer Text, Poor Me

I missed a specific situation back when I hacked at Markdown.

Because Markdown syntax allows HTML in code blocks, encoding every < as &lt; would also affect those in code blocks. This resulted in double encoding, i.e. &amp;lt;, which is rendered by the browser as &lt;—not pretty.

After discovering this during a related discussion with Sander on #foxymonkies, someone there—I believe it was sdwilsh—pointed me to Safe Markdown. Unfortunately, when I finally got that working, it didn’t seem to solve my problem at all.

Determined to find a solution, I dug into Markdown a bit deeper and found that all the encoding of code happens in Markdown_Parser’s encodeCode() function, rather unsurprisingly. Consequently, if I changed that function to return its input unchanged and did all the escaping in advance—which I was already doing—, I’d be home free.

Obviously, I could easily achieve this by extending the Markdown_Parser class. I ended up throwing everything related to comment formatting in there, including emoticons. The result is in Pwnt_Blog_CommentFormatter.

Once again, feel free to hunt for any shortcomings I may have overlooked.

Update: Actually, it’s better to put the emoticon stuff in a separate class, so Markdown and SmartyPants don’t get loaded for no reason.

Post a Comment

This contraption supports Gravatar, as well as Markdown with SmartyPants. If none of that made sense to you, feel free to ignore it and start typing.

  • :)
  • :D
  • ;)
  • :-O
  • :P
  • :@
  • :$
  • :S
  • :(
  • :'(
  • :|
  • :-#
  • 8-|
  • ^o)
  • :-*
  • +o(
  • :^)
  • *-)
  • 8-)
  • |-)
Disorientation
Continuity
Retributions
Automating OpenVPN Connection on Windows XP
blanky, sky, Tim, Geb, 12vpn, Tim, neecom
Simple Linear Regression with JFreeChart
Nicolas Machado, Sascha, Tim, Sascha, Tim, Sascha
De Canvascrack: een epiloog
Tim, Steven Noels
Lplayer for the Rest of Us
jesus2099, Tim, jesus2099, Tim, jesus2099, Tim, PixelPirate
Proximus, Universiteit Gent, Kafka: schrappen wat niet past
Tim, Bart Coppens, Tim, Steven, Tim, Femke
Colophonics