27Jun 2007
Using Markdown in MyTopix
There are a number of people out there who would much rather use the popular Markdown as a text parser as opposed to the standard bbCode tags that have become popular with most modern discussion boards. So, to satisfy this growing number of individuals, I've gone ahead and thrown together an extremely simple tutorial on how to implement this alternative text-to-html conversion tool into MyTopix.
Getting Markdown
Before you can use Markdown, you must first download the appropriate library. Since MyTopix is written in PHP, we cannot use the standard Markdown library which is written in Perl. Fortunately for us, Michel Fortin wrote a PHP-based alternative, so go get it!
Implementing Markdown
This is the easy part. Just drop the markdown.php file in MyTopix's library folder which is located directly beneath the MyTopix root directory %root%/lib/.
Before we start messing with core files, it's always a great idea to be on the safe side, I suggest creating a backup of the original file just in case you messed something up.
Next, you'll need to open the system's text parsing library and make a small change. Within the same library folder, open the file named parse.han.php in your favorite IDE. Within your IDE, scroll down to line 132. It should look like the following block of code:
$string = $this->parseBlocks ( $string );
$string = $this->parseSimple ( $string );
$string = $this->parseLinks ( $string );
You're going to want to replace it with:
require_once SYSTEM_PATH . 'lib/markdown.php';
$string = Markdown($string);
Save and upload the library, overwriting the older version to complete this mod. There, that's it. You're done!
Say What Now?
Yep, that's all there is to it. MyTopix makes this change simple because it parses the text during read time. To save resources, a lot of forum softwares out there convert text during post time and save the translated version in the database. Since the text is already translated, it doesn't need to go through a parser during read time. The only time it gets translated back to bbCode is when a user attempts to edit or quote an existing post.
MyTopix doesn't do this, so we really only have to change a couple lines to make this whole thing work. It even works well with emoticons turned on too.
I hope you enjoyed this tutorial! Till next time ...
As always, if anyone finds any issues, just let me know of them!