| 1 | = RedCloth - Textile parser for Ruby |
|---|
| 2 | |
|---|
| 3 | Homepage:: https://code.whytheluckystiff.net/redcloth/ |
|---|
| 4 | Author:: Jason Garber |
|---|
| 5 | Copyright:: (c) 2008 Jason Garber |
|---|
| 6 | |
|---|
| 7 | (See http://hobix.com/textile/ for a Textile reference.) |
|---|
| 8 | |
|---|
| 9 | = RedCloth |
|---|
| 10 | |
|---|
| 11 | RedCloth is a Ruby library for converting Textile into HTML. |
|---|
| 12 | |
|---|
| 13 | == Installing |
|---|
| 14 | |
|---|
| 15 | RedCloth can be installed via RubyGems: |
|---|
| 16 | |
|---|
| 17 | sudo gem install redcloth |
|---|
| 18 | |
|---|
| 19 | Or can be compiled from its Ragel source with <tt>rake compile</tt>. Ragel 6.1 |
|---|
| 20 | or greater is required to build RedCloth. |
|---|
| 21 | |
|---|
| 22 | == What is Textile? |
|---|
| 23 | |
|---|
| 24 | Textile is a simple formatting style for text |
|---|
| 25 | documents, loosely based on some HTML conventions. |
|---|
| 26 | |
|---|
| 27 | == Sample Textile Text |
|---|
| 28 | |
|---|
| 29 | h2. This is a title |
|---|
| 30 | |
|---|
| 31 | h3. This is a subhead |
|---|
| 32 | |
|---|
| 33 | This is a bit of paragraph. |
|---|
| 34 | |
|---|
| 35 | bq. This is a blockquote. |
|---|
| 36 | |
|---|
| 37 | = Writing Textile |
|---|
| 38 | |
|---|
| 39 | A Textile document consists of paragraphs. Paragraphs |
|---|
| 40 | can be specially formatted by adding a small instruction |
|---|
| 41 | to the beginning of the paragraph. |
|---|
| 42 | |
|---|
| 43 | h3. Header 3. |
|---|
| 44 | bq. Blockquote. |
|---|
| 45 | # Numeric list. |
|---|
| 46 | * Bulleted list. |
|---|
| 47 | |
|---|
| 48 | == Quick Phrase Modifiers |
|---|
| 49 | |
|---|
| 50 | Quick phrase modifiers are also included, to allow formatting |
|---|
| 51 | of small portions of text within a paragraph. |
|---|
| 52 | |
|---|
| 53 | \_emphasis\_ |
|---|
| 54 | \_\_italicized\_\_ |
|---|
| 55 | \*strong\* |
|---|
| 56 | \*\*bold\*\* |
|---|
| 57 | ??citation?? |
|---|
| 58 | -deleted text- |
|---|
| 59 | +inserted text+ |
|---|
| 60 | ^superscript^ |
|---|
| 61 | ~subscript~ |
|---|
| 62 | @code@ |
|---|
| 63 | %(classname)span% |
|---|
| 64 | |
|---|
| 65 | ==notextile== (leave text alone) |
|---|
| 66 | |
|---|
| 67 | == Links |
|---|
| 68 | |
|---|
| 69 | To make a hypertext link, put the link text in "quotation |
|---|
| 70 | marks" followed immediately by a colon and the URL of the link. |
|---|
| 71 | |
|---|
| 72 | Optional: text in (parentheses) following the link text, |
|---|
| 73 | but before the closing quotation mark, will become a title |
|---|
| 74 | attribute for the link, visible as a tool tip when a cursor is above it. |
|---|
| 75 | |
|---|
| 76 | Example: |
|---|
| 77 | |
|---|
| 78 | "This is a link (This is a title)":http://www.textism.com |
|---|
| 79 | |
|---|
| 80 | Will become: |
|---|
| 81 | |
|---|
| 82 | <a href="http://www.textism.com" title="This is a title">This is a link</a> |
|---|
| 83 | |
|---|
| 84 | == Images |
|---|
| 85 | |
|---|
| 86 | To insert an image, put the URL for the image inside exclamation marks. |
|---|
| 87 | |
|---|
| 88 | Optional: text that immediately follows the URL in (parentheses) will |
|---|
| 89 | be used as the Alt text for the image. Images on the web should always |
|---|
| 90 | have descriptive Alt text for the benefit of readers using non-graphical |
|---|
| 91 | browsers. |
|---|
| 92 | |
|---|
| 93 | Optional: place a colon followed by a URL immediately after the |
|---|
| 94 | closing ! to make the image into a link. |
|---|
| 95 | |
|---|
| 96 | Example: |
|---|
| 97 | |
|---|
| 98 | !http://www.textism.com/common/textist.gif(Textist)! |
|---|
| 99 | |
|---|
| 100 | Will become: |
|---|
| 101 | |
|---|
| 102 | <img src="http://www.textism.com/common/textist.gif" alt="Textist" /> |
|---|
| 103 | |
|---|
| 104 | With a link: |
|---|
| 105 | |
|---|
| 106 | !/common/textist.gif(Textist)!:http://textism.com |
|---|
| 107 | |
|---|
| 108 | Will become: |
|---|
| 109 | |
|---|
| 110 | <a href="http://textism.com"><img src="/common/textist.gif" alt="Textist" /></a> |
|---|
| 111 | |
|---|
| 112 | == Defining Acronyms |
|---|
| 113 | |
|---|
| 114 | HTML allows authors to define acronyms via the tag. The definition appears as a |
|---|
| 115 | tool tip when a cursor hovers over the acronym. A crucial aid to clear writing, |
|---|
| 116 | this should be used at least once for each acronym in documents where they appear. |
|---|
| 117 | |
|---|
| 118 | To quickly define an acronym in Textile, place the full text in (parentheses) |
|---|
| 119 | immediately following the acronym. |
|---|
| 120 | |
|---|
| 121 | Example: |
|---|
| 122 | |
|---|
| 123 | ACLU(American Civil Liberties Union) |
|---|
| 124 | |
|---|
| 125 | Will become: |
|---|
| 126 | |
|---|
| 127 | <acronym title="American Civil Liberties Union">ACLU</acronym> |
|---|
| 128 | |
|---|
| 129 | == Adding Tables |
|---|
| 130 | |
|---|
| 131 | In Textile, simple tables can be added by separating each column by |
|---|
| 132 | a pipe. |
|---|
| 133 | |
|---|
| 134 | |a|simple|table|row| |
|---|
| 135 | |And|Another|table|row| |
|---|
| 136 | |
|---|
| 137 | Styles are applied with curly braces. |
|---|
| 138 | |
|---|
| 139 | table{border:1px solid black}. |
|---|
| 140 | {background:#ddd;color:red}. |a|red|row| |
|---|
| 141 | |
|---|
| 142 | == Using RedCloth |
|---|
| 143 | |
|---|
| 144 | RedCloth is simply an extension of the String class, which can handle |
|---|
| 145 | Textile formatting. Use it like a String and output HTML with its |
|---|
| 146 | RedCloth#to_html method. |
|---|
| 147 | |
|---|
| 148 | doc = RedCloth.new " |
|---|
| 149 | |
|---|
| 150 | h2. Test document |
|---|
| 151 | |
|---|
| 152 | Just a simple test." |
|---|
| 153 | |
|---|
| 154 | puts doc.to_html |
|---|
| 155 | |
|---|