Once upon a time I used BBcode. CyberArmy and all its affiliated sites adopted it as de-facto standard for forums and articles, so consequently more or less all my articles are bbcoded.
I could copy and paste the BBcodeHelper I coded for this site, and it could be quite an interesting read for some people… well, tough luck: today I’d like to talk about Textile instead, which now I consider the answer to all text formatting problems.

If what I wrote up to here doesn’t make sense to you, I’m rambling about the apparent necessity and the undeniable need of web developers, content managers, and writers to use something else other than HTML for adding style and formatting text. What’s wrong with HTML? Nothing, it’s just too “tiresome” to use: you have to remember to close all tags, break lines, use the <strong> tag every time you want bold text, etc. etc.
Some people even freak out when you tell them that they have to use HTML in their text: “it’s just waaaaaay too difficult to learn and use” …things like that.

Whether you are scared to learn HTML, you don’t want to, or you know it but you’re too lazy to seriously thinking about manually use a markup language to write your article, I can say that you’ll definitely become addicted to Textile. What? WYSIWYG HTML editors?” – C’mon, let’s at least try to be serious :)
Why BBcode doesn’t help enough? Well, simply because I don’t see why [i]this[/i] is easier than <i>this</i>: unless you have a particular phobia for angular brackets, it seems quite similar to me!

What about _this_ instead? You use only two additional characters instead of seven. SEVEN. If I only want italcized text I honestly can’t imagine myself using more than two extra characters. It’s natural. It’s human.

Precisely. Textile is a “Humane web text generator™”, it’s simple, elegant and produces standard compliant XHTML code. Dean Allen should be worshipped by entire generations of web developers for inventing something so easy to use and so elegant at the same time. Maybe not worshipped, but for sure respected.

I won’t copy and paste the extremely useful TextileHelper for CakePHP either, simply because it’s 4085 lines long and it would be pointless: you can just get it and use it.

I’ll just include some examples of textile formatting…

Textile Code Result
*text* bold text
_text_ italicized text
@text@ fixed width text
"text":url linked text
!path/to/image! image

These are just some trivial examples. With textile you can also format text blocks, add custom CSS code and even float images or text! Tables? Sure, how do you think I created the table above?

| *Textile Code* | *Result* |
| @*text*@ | *bold* text |
| @_text_@ | _italicized_ text |
| <code>@text@<code>| @fixed width@ text|
| @"text":url@ | "linked":http://base--/ text |
| @!path/to/image!@ | image |

The simplest and most intuitive way possible!

Regardless, Textile is not perfect and may have some quirks, at least the CakePHP helper: the_undefined pointed out in a blog post that external links are opened in the same window, so he provided a patch to the textile helper to handle this situation.
I also noticed that sometimes empty style="" and class="" attributed are generated, which don’t do any particular harm, but they are not needed either… so here’s a quick fix to improve your Textile experience in CakePHP: You can use this function ideally in your customized textile helper, $data should be the return value of TextileHelper’s process() method.

function _fixTextile($data)
  $patterns = array( '/http://base--/', 
    '/  >/');
  $replaces = array($this->base, 
  return preg_replace($patterns, $replaces, $data);