<?xml version="1.0" encoding="UTF-8"?>
<article-node>
  <account-id type="integer">2</account-id>
  <author>Michael Slater</author>
  <aux>&lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; is rather verbose as a markup language, and having to include closing tags is messy and error-prone. We&amp;#8217;re all pretty much stuck with delivering &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; code from our web sites, but that doesn&amp;#8217;t mean we have to write in it. There are various markup approaches that are superior to &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; when it comes to content creation, and which can be used as source code from which to create &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt;. Two that are widely used are &amp;#8230;</aux>
  <body>&lt;p&gt;When I&amp;#8217;m writing content for the web, I hate dealing with &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; coding. &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; is rather verbose as a markup language, and having to include closing tags is messy and error-prone.&lt;/p&gt;
&lt;p&gt;We&amp;#8217;re all pretty much stuck with delivering &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; code from our web sites, but that doesn&amp;#8217;t mean we have to write in it. There are various markup approaches that are superior to &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; when it comes to content creation, and which can be used as source code from which to create &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt;. Two that are widely used are Textile and Markdown.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://textism.com/tools/textile/&quot;&gt;Textile&lt;/a&gt; was originally developed by Dean Allen for the TextPattern content management system and is now widely used in wikis and blogs. &lt;a href=&quot;http://daringfireball.net/projects/markdown/basics&quot;&gt;Markdown&lt;/a&gt;, created by John Gruber and Aaron Swartz, is an alternative that is conceptually similar but with a different syntax. Many of the popular blog engines provide a choice of Textile or Markdown (or &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt;) for posts and comments (this site offers Textile).&lt;/p&gt;
&lt;p&gt;In this article, I&amp;#8217;ll show the basics of Textile markup and how easy it is to use it in Rails applications.&lt;/p&gt;
&lt;h1&gt;What is Textile?&lt;/h1&gt;
&lt;p&gt;Textile strives to make text markup as clean and simple as possible. You don&amp;#8217;t have to put &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; in front of each paragraph; bare text is automatically surrounded by &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;/p&amp;gt;&lt;/code&gt; tags. To make a first-level heading, just start the line with @h1. @. For example:&lt;/p&gt;
&lt;pre&gt;
h1. This is a heading and will be wrapped in &amp;lt;h1&amp;gt; and &amp;lt;/h1&amp;gt; tags

This is a text paragraph and will be wrapped in &amp;lt;p&amp;gt; and &amp;lt;/p&amp;gt; tags.

This is another paragraph.
&lt;/pre&gt;
&lt;p&gt;And I bet you can guess how to make a second-level heading, or a third-level heading.&lt;/p&gt;
&lt;p&gt;You never need to use close tags; a pair of carriage returns automatically triggers the appropriate end tag. Quotes are automatically converted to open and close quotes; hyphens are converted to n-dashes (if there is a space on either side); and double hyphens are converted to m-dashes.&lt;/p&gt;
&lt;p&gt;To make text bold, surround it with asterisks; to make it italic, with underscores:&lt;/p&gt;
&lt;pre&gt;
*This text will render in bold*
_This text will render in italic*
_*This text will render in bold italic*_
&lt;/pre&gt;
&lt;p&gt;To add a link to a piece of text, surround the text in quotes, and follow it by a colon and the &lt;span class=&quot;caps&quot;&gt;URL&lt;/span&gt;:&lt;/p&gt;
&lt;pre&gt;
&quot;text to be linked&quot;:http://thisistheurl.com
&lt;/pre&gt;
&lt;p&gt;To include an image, type its &lt;span class=&quot;caps&quot;&gt;URL&lt;/span&gt; surrounded by exclamation points:&lt;/p&gt;
&lt;pre&gt;
!http://domain.com/path/to/image.jpg!
&lt;/pre&gt;
&lt;p&gt;To create a bullet list, start each line with an asterisk and a space, like this:&lt;/p&gt;
&lt;pre&gt;
* First item
* Second item
* Third item
&lt;/pre&gt;
&lt;p&gt;Want a nested bullet list? Just indent the asterisk by three spaces.&lt;/p&gt;
&lt;p&gt;There&amp;#8217;s more, but this should give you a feel for it. You can also use any &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; you want for things that Textile doesn&amp;#8217;t cover &amp;#8212; &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; code is simply passed through. For more details, see the &lt;a href=&quot;http://hobix.com/textile/&quot;&gt;Textile Reference&lt;/a&gt;. You can try out Textile online at the &lt;a href=&quot;http://www.textism.com/tools/textile/&quot;&gt;Textile home page&lt;/a&gt;.&lt;/p&gt;
&lt;h1&gt;Implementing Textile&lt;/h1&gt;
&lt;p&gt;There are Textile implementations for various environments. In my case, using Ruby on Rails, Textile is implemented by &lt;a href=&quot;http://whytheluckystiff.net&quot;&gt;whytheluckystiff&lt;/a&gt; &amp;#8217;s &lt;a href=&quot;http://whytheluckystiff.net/ruby/redcloth/&quot;&gt;RedCloth&lt;/a&gt; gem. (The current implementation does have some flaws, and a much-enhanced version called &lt;a href=&quot;http://code.whytheluckystiff.net/redcloth/wiki/SuperRedCloth&quot;&gt;Super RedCloth&lt;/a&gt; is in development.) To install, just enter the following in the console:&lt;/p&gt;
&lt;pre&gt;
gem install RedCloth
&lt;/pre&gt;
&lt;p&gt;With RedCloth installed, you create a new RedCloth object and pass some Textile-marked-up text to it:&lt;/p&gt;
&lt;pre&gt;
textile_styled_text =&quot;h1. This is an example of a heading in Textile&quot;
textile_object = RedCloth.new(textile_styled_text)
&lt;/pre&gt;
&lt;p&gt;Then, when you want to render this as &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt;, you simply use:&lt;/p&gt;
&lt;pre&gt;
html = textile_object.to_html
&lt;/pre&gt;
&lt;h1&gt;Making Textile Even Easier&lt;/h1&gt;
&lt;p&gt;That&amp;#8217;s pretty easy, but you can make it even easier. There&amp;#8217;s a Rails helper &amp;#8220;textilize,&amp;#8221; but thanks to  the &lt;a href=&quot;http://errtheblog.com/post/14&quot;&gt;acts_as_textiled&lt;/a&gt; plug from Chris Wanstrath, it&amp;#8217;s even easier than that. Install this plugin:&lt;/p&gt;
&lt;pre&gt;
ruby script/plugin install
 svn://errtheblog.com/svn/plugins/acts_as_textiled
&lt;/pre&gt;
&lt;p&gt;And then all you have to do is declare a model attribute as Textile-formatted in your model class:&lt;/p&gt;
&lt;pre&gt;
acts_as_textiled  :field_name
&lt;/pre&gt;
&lt;p&gt;That&amp;#8217;s it &amp;#8212; everything just works! (Remember, though, that you need to restart the server for the model change to take effect.) Textile marked up text is stored in the database. Form fields automatically show unrendered textile. But any other use of the model attribute automatically delivers the rendered &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; instead of the Textile source.&lt;/p&gt;
&lt;h1&gt;Markup without Coding&lt;/h1&gt;
&lt;p&gt;You can also simplify the entry of Textile markup by using the &lt;a href=&quot;http://slateinfo.blogs.wvu.edu/plugins/textile_editor_helper&quot;&gt;textile_editor_helper&lt;/a&gt; from Dave Olsen and Chris Scharf. This plug-in renders a set of icons for the common markup tasks in your form view, just above the text entry area:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/textile_helper.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;When you click an icon, JavaScript code inserts the appropriate markup into your text.&lt;/p&gt;
&lt;p&gt;To use this, first install the plugin:&lt;/p&gt;
&lt;pre&gt;
ruby script/plugin install
 http://svn.webtest.wvu.edu/repos/rails/plugins/textile_editor_helper

rake textile_editor_helper:install
&lt;/pre&gt;
&lt;p&gt;And then replace the text_area tag in the form in which the user enters the Textile-formatted text with textile_editor:&lt;/p&gt;
&lt;pre&gt;
&amp;lt;%= textile_editor 'object', 'field' -%&amp;gt;
&lt;/pre&gt;
&lt;p&gt;textile_editor takes all the same options as text_area.&lt;/p&gt;
&lt;p&gt;and at the end of the form add:&lt;/p&gt;
&lt;pre&gt;
&amp;lt;%= textile_editor_initialize -%&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Finally, if you don&amp;#8217;t already include prototype.js, you&amp;#8217;ll need to add that to your layout:&lt;/p&gt;
&lt;pre&gt;
&amp;lt;%= javascript_include_tag 'prototype.js' %&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Presto! Now you have a row of icons above the text area so your users don&amp;#8217;t have to remember any markup at all. They&amp;#8217;ll still see the markup in the text area (this is not a wysiwyg editor), which will help them learn the markup code.&lt;/p&gt;</body>
  <created-at type="datetime">2008-07-24T01:00:46-07:00</created-at>
  <created-by type="integer">1</created-by>
  <dy-schema-id type="integer" nil="true"></dy-schema-id>
  <dy-schema-type nil="true"></dy-schema-type>
  <filter-id nil="true"></filter-id>
  <flags type="integer">1</flags>
  <historic-id type="integer">6</historic-id>
  <id type="integer">6399</id>
  <kind-id type="integer">5019</kind-id>
  <lock-version type="integer">4</lock-version>
  <name>Easy Text Formatting with Textile</name>
  <owner-id type="integer" nil="true"></owner-id>
  <owner-type nil="true"></owner-type>
  <published-at type="datetime">2008-05-09T17:00:00-07:00</published-at>
  <rating type="integer">2</rating>
  <ref-count type="integer">0</ref-count>
  <sequence type="integer">0</sequence>
  <status type="integer">0</status>
  <updated-at type="datetime">2009-04-03T13:17:00-07:00</updated-at>
  <updated-by type="integer">1</updated-by>
  <url nil="true"></url>
  <user-id type="integer">1</user-id>
  <version type="integer">4</version>
  <workflow-task-status-id type="integer" nil="true"></workflow-task-status-id>
</article-node>
