all repos — h3rald @ 87d1386a6c49c4668ebab4623b793487ca6e9723

The sources of https://h3rald.com

content/articles/18.textile

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
----- 
permalink: "18"
filters_pre: 
- redcloth
title: Textiling
comments: []

date: 2006-04-21 09:39:03 +02:00
tags: []

type: article
toc: true
-----
Once upon a time I used "BBcode":http://en.wikipedia.org/wiki/BBCode. "CyberArmy":http://base--/bookmarks/view/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":http://base--/bookmarks/view/textile-reference/ 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(What You See is What You Get) 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 <code>[i]this[/i]</code> 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.

!<http://base--/img/pictures/pear2.gif!

 Precisely. Textile is a _"Humane web text generator(TM)"_, it's simple, elegant and produces standard compliant XHTML code. "Dean Allen":http://www.textism.com/about/ 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":http://cakeforge.org/projects/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 |
| <code>@text@</code> | @fixed width@ text|
| @"text":url@ | "linked":http://base--/ 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?

<pre><code>
| *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 |
</code></pre>

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":http://www.thinkingphp.org/2006/03/22/textile-a-personal-love-of-mine/ 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.

<pre><code>
function _fixTextile($data)
{
  $patterns = array( '/http://base--/', 
    '/style=""/', 
	'/class=""/', 
    '/  >/');
  $replaces = array($this->base, 
    '', 
    '', 
    '>');
  return preg_replace($patterns, $replaces, $data);  
}
</code></pre>