include_once("Textile.php");
$text = <<<EOT
h1. Heading
A _simple_ demonstration of Textile markup.
* One
* Two
* Three
"More information":http://www.textism.com/tools/textile is available.
EOT;
$textile = new Textile;
$html = $textile->process($text);
print $html;
A paragraph block. This is the default signature if no signature is explicitly given. Paragraphs are formatted with all the inline rules (see inline formatting) and each line receives the appropriate markup rules for the flavor of HTML in use. For example, newlines for XHTML content receive a <br /> tag at the end of the line (with the exception of the last line in the paragraph). Paragraph blocks are enclosed in a <p> tag.
A pre-formatted block of text. Textile will not add any HTML tags for individual lines. Whitespace is also preserved.
Note that within a "pre" block, < and > are translated into HTML entities automatically.
A "bc" signature is short for "block code", which implies a preformatted section like the 'pre' block, but it also gets a <code> tag (or for XHTML 2, a <blockcode> tag is used instead).
Note that within a "bc" block, < and > are translated into HTML entities automatically.
For composing HTML tables. See the "TABLES" section for more information.
A "bq" signature is short for "block quote". Paragraph text formatting is applied to these blocks and they are enclosed in a <blockquote> tag as well as <p> tags within.
Headline signatures that produce <h1>, etc. tags. You can adjust the relative output of these using the head_offset attribute.
A 'clear' signature is simply used to indicate that the next block should emit a CSS style attribute that clears any floating elements. The default behavior is to clear "both", but you can use the left (< or right >) alignment characters to indicate which side to clear.
A "dl" signature is short for "definition list". See the "LISTS" section for more information.
A "fn" signature is short for "footnote". You add a number following the "fn" keyword to number the footnote. Footnotes are output as paragraph tags but are given a special CSS class name which can be used to style them as you see fit.
All signatures should end with a period and be followed with a space. Inbetween the signature and the period, you may use several parameters to further customize the block. These include:
{style rule}
A CSS style rule. Style rules can span multiple lines.
[ll]
A language identifier (for a "lang" attribute).
(class)
or (#id)
or (class#id)
For CSS class and id attributes.
>
, <
, =
, <>
Modifier characters for alignment. Right-justification, left-justification, centered, and full-justification.
(
(one or more)Adds padding on the left. 1em per "(" character is applied. When combined with the align-left or align-right modifier, it makes the block float.
)
(one or more)Adds padding on the right. 1em per ")" character is applied. When combined with the align-left or align-right modifier, it makes the block float.
|filter|
or |filter|filter|filter|
A filter may be invoked to further format the text for this signature. If one or more filters are identified, the text will be processed first using the filters and then by Textile's own block formatting rules.
For example:
bq.. This is paragraph one of a block quote.
This is paragraph two of a block quote.
p. Now we're back to a regular paragraph.You can apply this technique to any signature (although for some it doesn't make sense, like "h1" for example). This is especially useful for "bc" blocks where your code may have many blank lines scattered through it.
p. Regular paragraph
== Escaped portion -- will not be formatted by Textile at all ==
p. Back to normal.You can also use this technique within a Textile block, temporarily disabling the inline formatting functions:
p. This is ==*a test*== of escaping.
*strong*
Translates into <strong>strong</strong>.
Translates into <em>emphasis</em>.
**bold**
Translates into <b>bold</b>.
__italics__
Translates into <i>italics</i>.
++bigger++
Translates into <big>bigger</big>.
--smaller--
Translates into: <small>smaller</small>.
-deleted text-
Translates into <del>deleted text</del>.
+inserted text+
Translates into <ins>inserted text</ins>.
^superscript^
Translates into <sup>superscript</sup>.
~subscript~
Translates into <sub>subscript</sub>.
%span%
Translates into <span>span</span>.
@code@
Translates into <code>code</code>. Note that within a '@...@' section, < and > are translated into HTML entities automatically.
Inline formatting operators accept the following modifiers:
{style rule}
A CSS style rule.
[ll]
A language identifier (for a "lang" attribute).
(class)
or (#id)
or (class#id)
For CSS class and id attributes.
Textile is *way* cool.
Textile is *_way_* cool.Now this won't work, because the formatting characters need whitespace before and after to be properly recognized.
Textile is way c*oo*l.However, you can supply braces or brackets to further clarify that you want to format, so this would work:
Textile is way c[*oo*]l.
And then he went on a long trip[1].By specifying the brackets with a number inside, Textile will recognize that as a footnote marker. It will replace that with a construct like this:
And then he went on a long trip1To supply the content of the footnote, place it at the end of your document using a "fn" block signature:
fn1. And there was much rejoicing.Which creates a paragraph that looks like this:
1 And there was much rejoicing.
"Text to display":http://example.comIn addition to this, you can add 'title' text to your link:
"Text to display (Title text)":http://example.comThe URL portion of the link supports relative paths as well as other protocols like ftp, mailto, news, telnet, etc.
"E-mail me please":mailto:someone@example.comYou can also use single quotes instead of double-quotes if you prefer. As with the inline formatting rules, a hyperlink must be surrounded by whitespace to be recognized (an exception to this is common punctuation which can reside at the end of the URL). If you have to place a URL next to some other text, use the bracket or brace trick to do that:
You["gotta":http://example.com]seethis!Textile supports an alternate way to compose links. You can optionally create a lookup list of links and refer to them separately. To do this, place one or more links in a block of it's own (it can be anywhere within your document):
[excom]http://example.com [exorg]http://example.orgFor a list like this, the text in the square brackets is used to uniquely identify the link given. To refer to that link, you would specify it like this:
"Text to display":excomOnce you've defined your link lookup table, you can use the identifiers any number of times.
!/path/to/image!Image attributes may also be specified:
!/path/to/image 10x20!Which will render an image 10 pixels wide and 20 pixels high. Another way to indicate width and height:
!/path/to/image 10w 20h!You may also redimension the image using a percentage.
!/path/to/image 20%x40%!Which will render the image at 20% of it's regular width and 40% of it's regular height.
Or specify one percentage to resize proprotionately:
!/path/to/image 20%!Alt text can be given as well:
!/path/to/image (Alt text)!The path of the image may refer to a locally hosted image or can be a full URL.
You can also use the following modifiers after the opening '!' character:
<
Align the image to the left (causes the image to float if CSS options are enabled).
>
Align the image to the right (causes the image to float if CSS options are enabled).
-
(dash)Aligns the image to the middle.
^
Aligns the image to the top.
~
(tilde)Aligns the image to the bottom.
{style rule}
Applies a CSS style rule to the image.
(class)
or (#id)
or (class#id)
Applies a CSS class and/or id to the image.
(
(one or more)Pads 1em on the left for each '(' character.
)
(one or more)Pads 1em on the right for each ')' character.
(c) (r) (tm)In addition to these, there are a whole set of character macros that are defined by default. All macros are enclosed in curly braces. These include:
{c|} or {|c} cent sign {L-} or {-L} pound sign {Y=} or {=Y} yen signMany of these macros can be guessed. For example:
{A'} or {'A} {a"} or {"a} {1/4} {*} {:)} {:(}
Simple lists:
* one * two * threeMulti-level lists:
* one ** one A ** one B *** one B1 * two ** two A ** two B * threeOrdered lists:
# one # two # threeStyling lists:
(class#id)* one * two * threeThe above sets the class and id attributes for the <ul> tag.
*(class#id) one * two * threeThe above sets the class and id attributes for the first <li> tag.
Definition lists:
dl. textile:a cloth, especially one manufactured by weaving or knitting; a fabric format:the arrangement of data for storage or display.Note that there is no space between the term and definition. The term must be at the start of the line (or following the "dl" signature as shown above).
From the simple:
|a|b|c| |1|2|3|To the complex:
table(fig). {color:red}_|Top|Row| {color:blue}|/2. Second|Row| |_{color:green}. Last|Modifiers can be specified for the table signature itself, for a table row (prior to the first '|' character) and for any cell (following the '|' for that cell). Note that for cells, a period followed with a space must be placed after any modifiers to distinguish the modifier from the cell content.
Modifiers allowed are:
{style rule}
A CSS style rule.
(class)
or (#id)
or (class#id)
A CSS class and/or id attribute.
(
(one or more)Adds 1em of padding to the left for each '(' character.
)
(one or more)Adds 1em of padding to the right for each ')' character.
<
Aligns to the left (floats to left for tables if combined with the ')' modifier).
>
Aligns to the right (floats to right for tables if combined with the '(' modifier).
=
Aligns to center (sets left, right margins to 'auto' for tables).
<>
For cells only. Justifies text.
^
For rows and cells only. Aligns to the top.
~
(tilde)For rows and cells only. Aligns to the bottom.
_
(underscore)Can be applied to a table row or cell to indicate a header row or cell.
\2
or \3
or \4
, etc.Used within cells to indicate a colspan of 2, 3, 4, etc. columns. When you see "\\", think "push forward".
/2
or /3
or /4
, etc.Used within cells to indicate a rowspan of 2, 3, 4, etc. rows. When you see "/", think "push downward".
When a cell is identified as a header cell and an alignment is specified, that becomes the default alignment for cells below it. You can always override this behavior by specifying an alignment for one of the lower cells.
"left" for left justified, "right" for right justified, "center" for centered text, "justify" for full-justified text.
"top" for top alignment, "bottom" for bottom alignment, "middle" for middle alignment.
"footnote" is applied to the paragraph tag for the footnote text itself. An id of "fn" plus the footnote number is placed on the paragraph for the footnote as well. For the footnote superscript tag, a class of "footnote" is used.
For a series of characters that are uppercased, a span is placed around them with a class of "caps".
Textile.php is a PHP port of Brad Choate's Text::Textile (Textile.pm) Perl module.
Textile.php was ported by Jim Riggs <textile at jimandlissa dot com>. Great care has been taken to leave the Perl code in much the same form as Textile.pm. While changes were required due to syntactical differences between Perl and PHP, much of the code was left intact (even if alternative syntax or code optimizations could have been made in PHP), even to the point where one can compare functions/subroutines side by side between the two implementations. This has been done to ensure compatibility, reduce the possibility of introducing errors, and simplify maintainance as one version or the other is updated.
Brad Choate <brad at bradchoate dot com>