I’m sure most people are familiar with the Textile text editing language used by many web-based tools to make creating and modifying web content more humane. I live and breathe Textile and use it pretty much wherever I can. Its simplicity and ability to get out of my way makes it the quickest way to edit XHTML that I know of.
I use Textile for writing blog entries like this one, I use it for leaving comments around the web on other people’s blogs. My wiki of choice utilises it, and I build Textile into an awful lot of the web apps I work on. It’s easy, quick, and simple to teach to a client or colleague. The one place I don’t have Textile, however, is in my favourite text editors and local applications. Until now…
Installing Textile on your Mac
If you’ve used rails you may have come across a ruby implementation of Textile called redcloth. The neat thing I noted about redcloth is that it runs as a stand-alone ruby script. You can invoke it from the command line and it’ll translate standard input into XHTML. You can then use any smart command line-aware apps to hook into this. Here’s how to get it running.
I’m going to assume that you’re running ruby 1.8 on your Mac. I think Tiger ships with version 1.8, but Panther only sported 1.6. The quick test:
Malachi:/ drew$ ruby -v
ruby 1.8.2 (2004-12-25) [powerpc-darwin8.0]
I’m running 1.8.2. You’d be advised to do similarly.
Redcloth
The next step is to download redcloth. After some searching and poking around on mailing lists, I found a good redcloth download which seamed to do the trick.
Decompress the download, navigate into the resulting folder, and run the ruby script install.rb using sudo (to give the script the privs it needs to copy things to the right folders).
Malachi:~/Downloads drew$ cd RedCloth-3.0.3
Malachi:~/Downloads/RedCloth-3.0.3 drew$ sudo ruby install.rb config
Malachi:~/Downloads/RedCloth-3.0.3 drew$ sudo ruby install.rb install
This script does a fair bit, but the crucial result is /usr/bin/redcloth – a program to which you can send your plaintext and get back XHTML.
Path to Ruby
One small change I had to make after installation was correcting the path to ruby that was at the top of /usr/bin/redcloth. Use a text editor (like nano or pico) and adjust the path to reflect where ruby lives on your system. Mine’s at /usr/bin/ruby/. You’ll need to sudo to edit this file.
Malachi:/ drew$ sudo nano /usr/bin/redcloth
(It’s Ctrl-X to save and get out of nano or pico).
Check that it’s all working by piping a small text string to the program:
Malachi:/ drew$ echo hello world | /usr/bin/redcloth
<p>hello world</p>
It all looks good. Next we have to put it to use more practically.
Using Textile in Textmate
I use Textmate as my weapon of choice at the moment (although I’m running an older version as they’ve really screwed it up lately). It has Commands which can be used to run scripts and such. For example, you could right a command to save, compile and then run your current document. Or, if you’re me, you can write a command to take the contents of the current document, run it through redcloth and bung the result in a new window.
In the Key Equivalent, I entered Ctrl-T as the option to invoke this particular command. This means that I can happily type away in a document, marking up with Textile syntax as I go. A simply keystroke launches a new document containing my transformed XHTML. Perfect!
Give it a go and let me know if you find any mistakes in the above.






Comments
jemaleddin$ sudo ruby install.rb configjemaleddin$ sudy ruby install.rb installOtherwise I get some message about reading the help and no global option for install.
sudoand notsudyWriting the instructions from memory has its pitfalls.
For the benefit of inept folk such as myself who happen not to use textmate, a less application-specific solution might be to use something along the lines of this crappy little applescript for in-clipboard conversion:
set theTextile to the clipboard as string
set the clipboard to (do shell script (“echo ” & theTextile & ” | /usr/bin/redcloth”))
I’ve been using TextMate since about March and have been loving it. I’d be interested in hearing what problems you are having with it as it’s been very stable for me and I’ve been running all the betas and even the new daily release builds that they’ve been putting out.
~/Desktop/downloads/RedCloth-3.0.4 deilers$ sudo ruby setup.rb config
~/Desktop/downloads/RedCloth-3.0.4 deilers$ sudo ruby setup.rb install
and there shouldn’t be a slash at the end of the shebang line:
#!/usr/bin/ruby
Also for Firefox users there is a GreaseMonkey script by Phil Wilson that allows you to write textile input into any textarea on any webpage.
(although I’m running an older version as they’ve really screwed it up lately)
What are you drinking? TM is better than ever.
Maybe you have to change syntaxes you made for yourself, but the new system is muuuuch better. Really. And TM is much more polished now.
Fred – back in September (when this was posted) the latest builds of TM were breaking code colouring and all sorts. The text editor is an important tool for me – if I download a version and I suddenly can’t work I don’t have time to mess about, I just roll back to the version which did work.
Since then I’ve had time to troubleshoot it a bit, and it seems that TextMate isn’t bundled with many languages by default any more. You have to go check them out from a subversion repository. Luckily I like TM enough to be bothered with that, and now I’m back running up-to-date builds and loving it. But it seems like a great way to put off new users. If I was trailling it for the first time, I’d give up before getting that far.
Which reminds me .. I should post about why I love TextMate.
And if you put
/usr/bin/redclothin Window – Web Preview – Show options – Pipe text through, it will show a live (controlled) preview of your textiled text. Woo-hoo!Many thanks for the tutorial.
Thanks a lot for your piece. I got this from another site:
put these lines into a file, say textile.sh:
#!/usr/bin/env ruby
# Textile’ise things.
# Take Textile markup on STDIN, and output HTML to STDOUT
require ‘rubygems’
require ‘redcloth’
print (RedCloth.new STDIN.read).to_html
Place in your path, and do a:
chmod +x textile.sh
Now you may do from the command line:
textile.sh < file.html > output.html
Or if you use the VIM editor:
:%!textile.sh
My need arose because some blogs like the very popular blogspot.com does not provide textile support.
Hope this helps!
rahul
btw, seems whenever i update MAC OS X, my rails and rubygems breaks. While trying to install using “sudo ruby install.rb config” i kept getting a loaderror install.rb not found !
So had then i resetup gems and did a gem install RedCloth.
Although the above commands will work, your download link is slightly out-of-date, Redcloth is now at version 3.0.4. An alternative which will always install the latest version would be:
sudo gem install redcloth --include-dependenciesThis requires you to have the Ruby Gems utility installed, but once that’s set up, the gem command makes installing almost any Ruby package that simple.