\
Textile
Textile parser.

Tags

Example

$parser = new Textile(); echo $parser->textileThis(‘h1. Hello World!’);

Summary
Methods Properties Constants
$a
$c
$fn
$s
No constants
Properties
$a
$a
?
$c
$c
?
$clas
$clas
Pattern for HTML classes and IDs.
$cspn
$cspn
?
$dimensionless_images
$dimensionless_images
Dimensionless images flag.
$doc_root
$doc_root
Server document root.
$doctype
$doctype
Target document type.
$fn
$fn
Array of footnotes
$glyph_replace
$glyph_replace
Glyph replacements.

An array of replacements used to insert typographic glyphs into the text. Each entry must have a corresponding entry in the $glyph_search array and may refer to values captured in the corresponding search regex.

Tags

See

Parser::$glyph_search

$glyph_search
$glyph_search
Patterns for finding glyphs.

An array of regex patterns used to find text features such as apostrophes, fractions and em-dashes. Each entry in this array must have a corresponding entry in the $glyph_replace array.

Tags

See

Parser::$glyph_replace

$hlgn
$hlgn
Pattern for horizontal align.
$lite
$lite
Lite mode.
$lnge
$lnge
Pattern for language attribute.
$max_span_depth
$max_span_depth
Maximum nesting level for inline elements.
$noimage
$noimage
Disallow images.
$pnct
$pnct
Pattern for punctation.
$rebuild_glyphs
$rebuild_glyphs
Indicates whether glyph substitution is required.

Dirty flag, set by setSymbol(), indicating the parser needs to rebuild the glyph substitutions before the next parse.

Tags

See

Parser::setSymbol()

$rel
$rel
HTML rel attribute used for links.
$relativeImagePrefix
$relativeImagePrefix
Relative image path.
$restricted
$restricted
Restricted mode.
$rspn
$rspn
?
$s
$s
?
$shelf
$shelf
Shelved content.

Stores fragments of the source text that have been parsed and require no more processing.

$styl
$styl
Pattern for style attribute.
$symbols
$symbols
Substitution symbols.
$url_schemes
$url_schemes
Accepted link protocols.
$ver
$ver
Version number.
$vlgn
$vlgn
Pattern for vertical align.
Methods
__construct()
__construct($doctype = 'xhtml')
Constructor.

Parameters

$doctypestring

The output document type, either ‘xhtml’ or ‘html5’

addPart()
addPart($mask, $name, $parts) : bool
Checks whether a component part can be added to a URI.

Parameters

$maskarray

An array of allowed component parts

$namestring

The component to add

$partsarray

An array of existing components to modify

Returns

\bool

TRUE if the component can be added

blocks()
blocks($text) : string
Splits the input textile text into blocks on double line-break boundaries and then

processes each block.

Parameters

$textstring

Textile source text

Returns

string

Input text with blocks processed

cleanAttribs()
cleanAttribs($in) : string
Cleans a HTML attribute value.

This method checks for presence of URL encoding in the value. If the number encoded characters exceeds the thereshold, the input is discarded. Otherwise the encoded instances are decoded.

This method also strips any “, ‘ and = characters from the given value. This method does not guarantee valid HTML or full sanitization.

Parameters

$instring

The input string

Returns

string

Cleaned string

cleanWhiteSpace()
cleanWhiteSpace($text) : string
Cleans up the textile input text, removing BOM and unifying line endings etc.

Parameters

$textstring

Input textile text

Returns

string

Cleaned version of the input

code()
code($text)

Parameters

$text

No description

decodeHigh()
decodeHigh($text, $charset = '"UTF-8"')

Parameters

$text

No description

$charset

No description

doSpecial()
doSpecial($text, $start, $end, $method = 'fSpecial')

Parameters

$text

No description

$start

No description

$end

No description

$method

No description

encodeHTML()
encodeHTML($str, $quotes = 1) : string
Convert special characters to HTML entities.

This method’s functinality is identical to PHP’s own htmlspecialchars(). In Textile this is used for sanitizing the input.

Tags

See

htmlspecialchars()

Parameters

$strstring

The string to encode

$quotes\bool

Encode quotes

Returns

string

Encoded string

encodeHigh()
encodeHigh($text, $charset = '"UTF-8"')

Parameters

$text

No description

$charset

No description

fBlock()
fBlock($m)

Parameters

$m

No description

fCode()
fCode($m)

Parameters

$m

No description

fImage()
fImage($m)

Parameters

$m

No description

fLink()
fLink($m)

Parameters

$m

No description

fNoteLists()
fNoteLists($m)

Parameters

$m

No description

fParseHTMLComments()
fParseHTMLComments($m)

Parameters

$m

No description

fParseNoteDefs()
fParseNoteDefs($m)

Parameters

$m

No description

fParseNoteRefs()
fParseNoteRefs($m)

Parameters

$m

No description

fPre()
fPre($m)

Parameters

$m

No description

fRedclothList()
fRedclothList($m) : string
Constructs a HTML definition list from a RedCloth-style definition structure.

This method is used by Parser::redclothLists() to process found definition list structures.

Tags

See

Parser::redclothLists()

Parameters

$marray

No description

Returns

string

HTML definition list

fRetrieveCloseTags()
fRetrieveCloseTags($m)

Parameters

$m

No description

fRetrieveOpenTags()
fRetrieveOpenTags($m)

Parameters

$m

No description

fSpan()
fSpan($m)

Parameters

$m

No description

fSpecial()
fSpecial($m)

Parameters

$m

No description

fTable()
fTable($matches) : string
Constructs a HTML table from a textile table structure.

This method is used by Parser::tables() to process found table structures.

Tags

See

Parser::tables()

Parameters

$matchesarray

No description

Returns

string

HTML table

fTextile()
fTextile($m)

Parameters

$m

No description

fTextileList()
fTextileList($m) : string
Constructs a HTML list from a textile list structure.

This method is used by Parser::textileLists() to process found list structures.

Tags

See

Parser::textileLists()

Parameters

$marray

No description

Returns

string

HTML list

footnoteID()
footnoteID($m)

Parameters

$m

No description

footnoteRefs()
footnoteRefs($text)

Parameters

$text

No description

formatFootnote()
formatFootnote($marker, $atts = '', $anchor = true)

Parameters

$marker

No description

$atts

No description

$anchor

No description

getDimensionlessImages()
getDimensionlessImages() : bool
Allows access to the dimensionless images flag.

Returns

\bool

state of the $dimensionless_images flag.

getHTMLComments()
getHTMLComments($text)

Parameters

$text

No description

getRefs()
getRefs($text) : string
Finds URI aliases within the textile source text and pulls them out of it and stores them in an internal

link alias cache so that they can be referenced from any links in the document.

This parse happens before the link parsing takes place.

Parameters

$textstring

textile document

Returns

string

The textile document with any URI aliases/refs removed.

getSymbol()
getSymbol($name = null) : array|string
Gets a symbol definitions.

This method can be used to get a symbol definition, or an array containg the full symbol table.

Parameters

$name\string|null

The name of the symbol, or NULL if requesting the symbol table

Returns

\array|string

The symbol table or the requested symbol

getVersion()
getVersion() : string
Returns the internal version of this instance of textile.

Tags

Access

public

Returns

string

Version

glyphs()
glyphs($text) : string
Perfoms typographical glyph replacements within the input textile text.

The source text is split across HTML-like tags in order to avoid attempting glyph replacements within tags.

Parameters

$textstring

Input textile source text

Returns

string
graf()
graf($text)

Parameters

$text

No description

hAlign()
hAlign($in) : string
Translates alignment tag into corresponding CSS text-align property value.

Parameters

$instring

The Textile alignment tag

Returns

string

CSS text-align value

hasRawText()
hasRawText($text) : bool
Checks whether the text is not enclosed by a block tag.

Parameters

$textstring

The input string

Returns

\bool

TRUE if the text is not enclosed

images()
images($text) : string
Parses the input textile document for images and generates img HTML tags for each one found, caching the

generated img tag internally and replacing the textile image with a token to the cached tag.

Parameters

$textstring

Textile source text

Returns

string

The input document with images pulled out and replaced with tokens

isRelURL()
isRelURL($url) : bool
Checks if an URL is relative.

The given URL is considered relative if it doesn’t contain scheme and hostname.

Parameters

$urlstring

The URL

Returns

\bool

TRUE if relative, FALSE otherwise

liType()
liType($in) : string
Determines the list type from the textile input symbol.

Parameters

$instring

Textile input containing the possible list marker

Returns

string

Either ‘d’, ‘o’, ‘u’

links()
links($text) : string
Initiates recognition and conversion of links in the source document.

Parameters

$textstring

The source textile text

Returns

string

The document with tokens inserted representing the links

makeBackrefLink()
makeBackrefLink($info, $g_links, $i)

Parameters

$info

No description

$g_links

No description

$i

No description

newTag()
newTag($name, $atts, $selfclosing = true) : \Netcarver\Textile\Tag
Constructs a HTML tag from an object.

This is a helper method that creates a new instance.

Parameters

$namestring

The HTML element name

$attsarray

HTML attributes applied to the tag

$selfclosing\bool

Determines if the tag should be selfclosing

Returns

\Netcarver\Textile\Tag
noTextile()
noTextile($text)

Parameters

$text

No description

noteRefs()
noteRefs($text)

Parameters

$text

No description

parseAttribs()
parseAttribs($in, $element = '""', $include_id = 1, $autoclass = '') : string
Parses Textile attributes.

Tags

See

Parser::parseAttribsToArray()

Parameters

$instring

The Textile attribute string to be parsed

$elementstring

Focus the routine to interpret the attributes as applying to a specific HTML tag

$include_idint

A value interpreted as a true when cast to bool allows ids to be included in the output

$autoclassstring

An additional class or classes to be applied to the output

Returns

string

HTML attribute list

parseAttribsToArray()
parseAttribsToArray($in, $element = '""', $include_id = 1, $autoclass = '') : array
Parses Textile attributes into an array.

Tags

See

Parser::parseAttribs()

Parameters

$instring

The Textile attribute string to be parsed

$elementstring

Focus the routine to interpret the attributes as applying to a specific HTML tag

$include_idint

A value interpreted as a true when cast to bool allows ids to be included in the output

$autoclassstring

An additional class or classes to be applied to the output

Returns

array

HTML attributes as key => value mappings

parseURI()
parseURI($uri, $m) : bool
Parses URI into component parts.

This method splits a URI-like string apart into component parts, while also providing validation.

Tags

Link

http://tools.ietf.org/html/rfc3986#appendix-B

Parameters

$uristring

The string to pick apart (if possible)

$marray

Reference to an array the URI component parts are assigned to

Returns

\bool

TRUE if the string validates as a URI

placeNoteLists()
placeNoteLists($text)

Parameters

$text

No description

prepGlyphs()
prepGlyphs()
Prepares the glyph patterns from the symbol table.

Tags

See

Parser::setSymbol()

See

Parser::getSymbol()

prepare()
prepare($lite, $noimage, $rel)
Prepares the parser for parsing.

This method prepares the transient internal state of Textile parser in preparation for parsing a new document.

Parameters

$lite\bool

Controls lite mode

$noimage\bool

Disallow images

$relstring

A relationship attribute applied to links

rEncodeHTML()
rEncodeHTML($str, $quotes = 1) : string
Convert special characters to HTML entities.

This is identical to encodeHTML(), but takes restricted mode into account. When in restricted mode, only encodes quotes no matter what the $quotes is set to.

Tags

See

Parser::encodeHTML()

Parameters

$strstring

The string to encode

$quotes\bool

Encode quotes

Returns

string

Encoded string

rebuildURI()
rebuildURI($parts, $mask = 'scheme,authority,path,query,fragment', $encode = true) : string
Rebuild a URI from parsed parts and a mask.

Algorithm based on example from http://tools.ietf.org/html/rfc3986#section-5.3

Parameters

$partsarray

Full array of URI parts

$maskstring

Comma separated list of URI parts to include in the rebuilt URI

$encode\bool

Flag to control encoding of the path part of the rebuilt URI

Returns

string

The rebuilt URI

redclothLists()
redclothLists($text) : string
Parses RedCloth-style definition lists into HTML.

Parameters

$textstring

The textile input

Returns

string

The parsed text

refs()
refs($m)

Parameters

$m

No description

relURL()
relURL($url)

Parameters

$url

No description

replaceGlyphs()
replaceGlyphs($text)

Parameters

$text

No description

replaceMarkers()
replaceMarkers($text, $replacements)

Parameters

$text

No description

$replacements

No description

retrieve()
retrieve($text)

Parameters

$text

No description

retrieveTags()
retrieveTags($text)

Parameters

$text

No description

retrieveURL()
retrieveURL($m)

Parameters

$m

No description

retrieveURLs()
retrieveURLs($text)

Parameters

$text

No description

setDimensionlessImages()
setDimensionlessImages($dimensionless = true) : object
Allows a client to better support responsive designs by turning on or off

image dimensions when parsing a textile image tag with a relative path.

By default (if this method is not called) image dimensions will be included for relative images (if possible).

Tags

Example

$parser = new Parser(); $html = $parser->setDimensionlessImages()->textileThis($input);

Parameters

$dimensionless\bool

true=>omit image dimensions, false=>include dimensions

Returns

object

$this

setRelativeImagePrefix()
setRelativeImagePrefix($prefix = '') : object
Sets base image directory path.

This is used when Textile is supplied with a relative image path. Allows client systems to have textile convert relative image paths to absolute or prefixed paths. This method is used to set that base path, usually a absolute HTTP address pointing to a directory.

Parameters

$prefixstring

The string to prefix all relative image paths with

Returns

object

$this $parser->setRelativeImagePrefix(‘http://static.example.com/’);

setSymbol()
setSymbol($name, $value) : object
Defines a substitution symbol.

Call this you need to redefine a substitution symbol to be used when parsing a textile document.

Parameters

$namestring

Name of the symbol to assign a new value to.

$valuestring

New value for the symbol.

Returns

object

$this

shelve()
shelve($val) : string
Shelves parsed content.

Stores away a fragment of the source text that have been parsed and requires no more processing.

Parameters

$valstring

The content

Returns

string

The fragment’s unique reference ID

shelveURL()
shelveURL($text) : string
Shelves parsed URLs.

Stores away a URL fragments that have been parsed and requires no more processing.

Parameters

$textstring

The URL

Returns

string

The fragment’s unique reference ID

spans()
spans($text) : string
Replaces textile spans with their equivalent HTML inline tags.

Parameters

$textstring

The textile document to perform the replacements in.

Returns

string

The textile document with spans replaced by their HTML inline equivalents

storeTags()
storeTags($opentag, $closetag = '')

Parameters

$opentag

No description

$closetag

No description

tables()
tables($text) : string
Parses textile table structures into HTML.

Parameters

$textstring

The textile input

Returns

string

The parsed text

textileCommon()
textileCommon($text, $lite) : string
Parses Textile syntax.

This method performs common parse actions.

Parameters

$textstring

The input to parses

$lite\bool

Controls lite mode

Returns

string

Parsed input

textileEncode()
textileEncode($text) : string
Encodes the given text.

Tags

Example

$parser = new Parser(); $parser->textileEncode(‘Some content to encode.’);

Parameters

$textstring

The text to be encoded

Returns

string

The encoded text

textileLists()
textileLists($text) : string
Parses textile list structures into HTML.

Searches for ordered, un-ordered and definition lists in the textile input and generates HTML lists for them.

Parameters

$textstring

The textile input

Returns

string

The parsed text

textileRestricted()
textileRestricted($text, $lite = 1, $noimage = 1, $rel = 'nofollow') : string
Parses the given Textile input in restricted mode.

This method should be used for any untrusted user input, including comments or forum posts.

This method escapes any raw HTML input, links only whitelisted URL schemes and by default also prevents the use of images and extra Textile formatting, accepting only paragraphs and blockquotes as valid block tags.

Tags

See

Parser::textileThis()

Example

$parser = new Parser(); echo $parser->textileRestricted(‘h1. Hello World!’);

Parameters

$textstring

The Textile input to parse

$lite\bool

Controls lite mode, allowing extra formatting

$noimage\bool

Allow images

$relstring

Relationship attribute applied to generated links

Returns

string

Parsed $text

textileThis()
textileThis($text, $lite = '', $encode = '', $noimage = '', $strict = '', $rel = '') : string
Parses the given Textile input in un-restricted mode.

Tags

See

Parser::textileRestricted()

Example

$parser = new Parser(); echo $parser->textileThis(‘h1. Hello World!’);

Parameters

$textstring

The Textile input to parse

$lite\bool

Switch to lite mode

$encode\bool

Encode input and return

$noimage\bool

Disables images

$strict\bool

FALSE to strip whitespace before parsing

$relstring

Relationship attribute applied to generated links

Returns

string

Parsed $text

vAlign()
vAlign($in) : string
Translates vertical alignment tag into corresponding CSS vertical-align property value.

Parameters

$instring

The Textile alignment tag

Returns

string

CSS vertical-align value