Text_Wiki
[ class tree: Text_Wiki ] [ index: Text_Wiki ] [ all elements ]

Class: Text_Wiki_Rule

Source Location: /Text_Wiki-0.12.1/Text/Wiki/Rule.php

Class Overview


Baseline rule class for extension into a "real" wiki rule.


Author(s):

Variables

Methods


Child classes:

Text_Wiki_Rule_colortext
This class implements a Text_Wiki_Rule to find source text marked for coloring.
Text_Wiki_Rule_bold
This class implements a Text_Wiki_Rule to find source text marked for
Text_Wiki_Rule_entities
This class implements a Text_Wiki_Rule to convert HTML entities in the source text.
Text_Wiki_Rule_toc
This class implements a Text_Wiki_Rule to find all heading tokens and build a table of contents. The [[toc]] tag gets replaced with a list of all the level-2 through level-6 headings.
Text_Wiki_Rule_phplookup
This class implements a Text_Wiki_Rule to find source text marked for lookup in the PHP online manual.
Text_Wiki_Rule_url
This class implements a Text_Wiki_Rule to find source text marked as a
Text_Wiki_Rule_break
This class implements a Text_Wiki_Rule to mark forced line breaks in the source text.
Text_Wiki_Rule_center
This class implements a Text_Wiki_Rule to find lines marked for centering.
Text_Wiki_Rule_image
This class implements a Text_Wiki_Rule to embed the contents of a URL inside the page. Typically used to get script output.
Text_Wiki_Rule_interwiki
This class implements a Text_Wiki_Rule to find source text marked as an Interwiki link. See the regex for a detailed explanation of the text matching procedure; e.g., "InterWikiName:PageName".
Text_Wiki_Rule_strong
This class implements a Text_Wiki_Rule to find source text marked for
Text_Wiki_Rule_table
This class implements a Text_Wiki_Rule to find source text marked as a
Text_Wiki_Rule_emphasis
This class implements a Text_Wiki_Rule to find source text marked for emphasis (italics) as defined by text surrounded by two single-quotes.
Text_Wiki_Rule_tt
This class implements a Text_Wiki_Rule to find source text marked for teletype (monospace) as defined by text surrounded by two curly braces. On parsing, the text itself is left in place, but the starting and ending instances of curly braces are replaced with tokens.
Text_Wiki_Rule_tighten
This rule removes 3+ consecutive newlines from the source text, replacing them with 2 newlines instead.
Text_Wiki_Rule_paragraph
This class implements a Text_Wiki rule to find sections of the source text that are paragraphs. A para is any line not starting with a token delimiter, followed by two newlines.
Text_Wiki_Rule_deflist
This class implements a Text_Wiki_Rule to find source text marked as a definition list. In short, if a line starts with ':' then it is a definition list item; another ':' on the same lines indicates the end of the definition term and the beginning of the definition narrative.
Text_Wiki_Rule_wikilink
This class implements a Text_Wiki_Rule to find source text marked as a wiki page name and automatically create a link to that page.
Text_Wiki_Rule_html
This class implements a Text_Wiki_Rule to find source text marked as HTML to be redndred as-is. The block start is marked by <html> on its own line, and the block end is marked by </html> on its own line.
Text_Wiki_Rule_superscript
This class implements a Text_Wiki_Rule to find source text marked for
Text_Wiki_Rule_newline
This class implements a Text_Wiki_Rule to mark implied line breaks in the source text, usually a single carriage return in the middle of a paragraph or block-quoted text.
Text_Wiki_Rule_raw
This class implements a Text_Wiki rule to find sections of the source text that are not to be processed by Text_Wiki. These blocks of "raw" text will be rendered as they were found.
Text_Wiki_Rule_list
This class implements a Text_Wiki_Rule to find source text marked as
Text_Wiki_Rule_include
This class implements a Text_Wiki_Rule to include the results of a
Text_Wiki_Rule_italic
This class implements a Text_Wiki_Rule to find source text marked for emphasis (italics) as defined by text surrounded by two single-quotes.
Text_Wiki_Rule_phpcode
This class implements a Text_Wiki_Rule to find sections marked as code
Text_Wiki_Rule_revise
This class implements a Text_Wiki_Rule to find source text marked for revision.
Text_Wiki_Rule_freelink
This class implements a Text_Wiki_Rule to find source text marked as a wiki freelink, and automatically create a link to that page.
Text_Wiki_Rule_delimiter
This class implements a Text_Wiki_Rule to find instances of the delimiter character already embedded in the source text; it extracts them and replaces them with a delimited token, then renders them as the delimiter itself when the target format is XHTML.
Text_Wiki_Rule_code
This class implements a Text_Wiki_Rule to find sections marked as code
Text_Wiki_Rule_horiz
This class implements a Text_Wiki_Rule to find source text marked to be a horizontal rule, as defined by four dashed on their own line.
Text_Wiki_Rule_embed
This class implements a Text_Wiki_Rule to embed the contents of a URL inside the page at render-time. Typically used to get script output.
Text_Wiki_Rule_prefilter
This class implements a Text_Wiki_Rule to "pre-filter" source text so that line endings are consistently \n, lines ending in a backslash \ are concatenated with the next line, and tabs are converted to spaces.
Text_Wiki_Rule_heading
This class implements a Text_Wiki_Rule to find source text marked to
Text_Wiki_Rule_blockquote
This class implements a Text_Wiki_Rule to find source text marked as a blockquote, identified by any number of greater-than signs '>' at the start of the line, followed by a space, and then the quote text; each '>' indicates an additional level of quoting.

Inherited Variables

Inherited Methods


Class Details

[line 57]
Baseline rule class for extension into a "real" wiki rule.

Text_Wiki_Rule classes do not stand on their own; they are called by a Text_Wiki object, typcially in the transform()method. Each rule class performs three main activities: parse, process, and render.

The parse() method takes a regex and applies it to the whole block of source text at one time. Each match is sent as $matches to the process() method.

The process() method acts on the matched text from the source, and then processes the source text is some way. This may mean the creation of a delimited token using addToken(). In every case, the process() method returns the text that should replace the matched text from parse().

Finally, the render*() methods take any token created by the rule and creates output text matching a specific format. Individual rules may or may not have options for specific formats.

Typically, the extended rule only needs to define the process() and render() methods; the parse() method is generally the same from rule to rule, and has been included here. However, there is no reason that rules cannot override these methods, so long as the new methods operate in substantially the same manner; similarly, the rule need not generate any tokens at all, and may use a specialized parse() method to filter the source text. See the default rule classes for many examples.



[ Top ]


Class Variables

$regex =  null

[line 73]

The regular expression used to parse the source text and find matches conforming to this rule. Used by the parse() method.

Type:   string


[ Top ]

$_wiki =  null

[line 87]

A reference to the calling Text_Wiki object. This is needed so that each rule has access to the same source text, token set, URLs, interwiki maps, page names, etc.
  • Access: public

Type:   object


[ Top ]



Method Detail

Text_Wiki_Rule (Constructor)   [line 129]

Text_Wiki_Rule Text_Wiki_Rule( object &$obj, string $name)

Constructor for the rule.
  • Access: public

Parameters:

object   &$obj   —  The calling "parent" Text_Wiki object.
string   $name   —  The token name to use for this rule.

[ Top ]

addToken   [line 167]

string|int addToken( [array $options = array()], [boolean $id_only = false])

Add a token to the Text_Wiki tokens array, and return a delimited token number.
  • Return: By default, return the number of the newly-created token array element with a delimiter prefix and suffix; however, if $id_only is set to true, return only the token number (no delimiters).
  • Access: public

Parameters:

array   $options   —  An associative array of options for the new token array element. The keys and values are specific to the rule, and may or may not be common to other rule options. Typical options keys are 'text' and 'type' but may include others.
boolean   $id_only   —  If true, return only the token number, not a delimited token string.

[ Top ]

getMacroArgs   [line 313]

array getMacroArgs( string $text)

Simple method to extract 'option="value"' portions of wiki markup, typically used only in macros.

The syntax is pretty strict; there can be no spaces between the option name, the equals, and the first double-quote; the value must be surrounded by double-quotes. You can escape characters in the value with a backslash, and the backslash will be stripped for you.

  • Return: An associative array of key-value pairs where the key is the option name and the value is the option value.
  • Access: public

Parameters:

string   $text   —  The "macro options" portion of macro markup.

[ Top ]

parse   [line 238]

void parse( )

Simple parsing method to apply the rule's regular expression to the source text, pass every match to the process() method, and replace the matched text with the results of the processing.
  • Access: public

Overridden in child classes as:

Text_Wiki_Rule_entities::parse()
Simple parsing method to apply the rule.
Text_Wiki_Rule_toc::parse()
Custom parsing (have to process heading entries first).
Text_Wiki_Rule_url::parse()
A somewhat complex parsing method to find three different kinds of URLs in the source text.
Text_Wiki_Rule_interwiki::parse()
Parser. We override the standard parser so we can find both described interwiki links and standalone links.
Text_Wiki_Rule_tighten::parse()
Simple parsing method to apply tightening directly to the tokens array.
Text_Wiki_Rule_wikilink::parse()
First parses for described links, then for standalone links.
Text_Wiki_Rule_prefilter::parse()
Simple parsing method to apply the rule directly to the source text.

[ Top ]

process   [line 266]

string process( &$matches, array $matches)

Simple processing mathod to take matched text and generate replacement text. This is one of the methods you will definitely want to override in your rule class extensions.
  • Return: The processed text replacement; defaults to the full matched string (i.e., no changes to the text).
  • Access: public

Overridden in child classes as:

Text_Wiki_Rule_colortext::process()
Generates a replacement for the matched text. Token options are:
Text_Wiki_Rule_bold::process()
Generates a replacement for the matched text. Token options are:
Text_Wiki_Rule_toc::process()
Generates a replacement for the matched text. Token options are:
Text_Wiki_Rule_phplookup::process()
Generates a replacement for the matched text. Token options are:
Text_Wiki_Rule_url::process()
Process inline URLs and return replacement text with a delimited token.
Text_Wiki_Rule_break::process()
Generates a replacement token for the matched text.
Text_Wiki_Rule_center::process()
Generates a token entry for the matched text.
Text_Wiki_Rule_image::process()
Generates a token entry for the matched text. Token options are:
Text_Wiki_Rule_interwiki::process()
Generates a replacement for the matched standalone interwiki text.
Text_Wiki_Rule_strong::process()
Generates a replacement for the matched text. Token options are:
Text_Wiki_Rule_table::process()
Generates a replacement for the matched text. Token options are:
Text_Wiki_Rule_emphasis::process()
Generates a replacement for the matched text. Token options are:
Text_Wiki_Rule_tt::process()
Generates a replacement for the matched text. Token options are:
Text_Wiki_Rule_paragraph::process()
Generates a token entry for the matched text. Token options are:
Text_Wiki_Rule_deflist::process()
Generates a replacement for the matched text. Token options are:
Text_Wiki_Rule_wikilink::process()
Generates a replacement for standalone links. Token options are:
Text_Wiki_Rule_html::process()
Generates a replacement for the matched text. Token options are:
Text_Wiki_Rule_superscript::process()
Generates a replacement for the matched text. Token options are:
Text_Wiki_Rule_newline::process()
Generates a replacement token for the matched text.
Text_Wiki_Rule_raw::process()
Generates a token entry for the matched text. Token options are:
Text_Wiki_Rule_list::process()
Generates a replacement for the matched text. Token options are:
Text_Wiki_Rule_include::process()
Includes the results of the script directly into the source; the output will subsequently be parsed by the remaining Text_Wiki rules.
Text_Wiki_Rule_italic::process()
Generates a replacement for the matched text. Token options are:
Text_Wiki_Rule_phpcode::process()
Generates a token entry for the matched text. Token options are:
Text_Wiki_Rule_revise::process()
Generates a replacement for the matched text. Token options are:
Text_Wiki_Rule_freelink::process()
Generates a replacement for the matched text. Token options are:
Text_Wiki_Rule_delimiter::process()
Generates a token entry for the matched text. Token options are:
Text_Wiki_Rule_code::process()
Generates a token entry for the matched text. Token options are:
Text_Wiki_Rule_horiz::process()
Generates a replacement token for the matched text.
Text_Wiki_Rule_embed::process()
Generates a token entry for the matched text. Token options are:
Text_Wiki_Rule_heading::process()
Generates a replacement for the matched text. Token options are:
Text_Wiki_Rule_blockquote::process()
Generates a replacement for the matched text. Token options are:

Parameters:

array   $matches   —  An array of matches from the parse() method as generated by preg_replace_callback. $matches[0] is the full matched string, $matches[1] is the first matched pattern, $matches[2] is the second matched pattern, and so on.
   &$matches   — 

[ Top ]

renderXhtml   [line 287]

string renderXhtml( array $options)

Simple rendering method to take a set of token options and generate replacement text for it. This is another method you will definitely want to override in your rule subclass extensions.
  • Return: The text rendered from the token options; by default, no text is returned. You should change this in your subclass. ;-)
  • Access: public

Overridden in child classes as:

Text_Wiki_Rule_colortext::renderXhtml()
Renders a token into text matching the requested format.
Text_Wiki_Rule_bold::renderXhtml()
Renders a token into text matching the requested format.
Text_Wiki_Rule_toc::renderXhtml()
Renders a token into text matching the requested format.
Text_Wiki_Rule_phplookup::renderXhtml()
Renders a token into text matching the requested format.
Text_Wiki_Rule_url::renderXhtml()
Renders a token into text matching the requested format.
Text_Wiki_Rule_break::renderXhtml()
Renders a token into text matching the requested format.
Text_Wiki_Rule_center::renderXhtml()
Renders a token into text matching the requested format.
Text_Wiki_Rule_image::renderXhtml()
Renders a token into text matching the requested format.
Text_Wiki_Rule_interwiki::renderXhtml()
Renders a token into text matching the requested format.
Text_Wiki_Rule_strong::renderXhtml()
Renders a token into text matching the requested format.
Text_Wiki_Rule_table::renderXhtml()
Renders a token into text matching the requested format.
Text_Wiki_Rule_emphasis::renderXhtml()
Renders a token into text matching the requested format.
Text_Wiki_Rule_tt::renderXhtml()
Renders a token into text matching the requested format.
Text_Wiki_Rule_paragraph::renderXhtml()
Renders a token into text matching the requested format.
Text_Wiki_Rule_deflist::renderXhtml()
Renders a token into text matching the requested format.
Text_Wiki_Rule_wikilink::renderXhtml()
Renders a token into text matching the requested format.
Text_Wiki_Rule_html::renderXhtml()
Renders a token into text matching the requested format.
Text_Wiki_Rule_superscript::renderXhtml()
Renders a token into text matching the requested format.
Text_Wiki_Rule_newline::renderXhtml()
Renders a token into text matching the requested format.
Text_Wiki_Rule_raw::renderXhtml()
Renders a token into text matching the requested format.
Text_Wiki_Rule_list::renderXhtml()
Renders a token into text matching the requested format.
Text_Wiki_Rule_italic::renderXhtml()
Renders a token into text matching the requested format.
Text_Wiki_Rule_phpcode::renderXhtml()
Renders a token into text matching the requested format.
Text_Wiki_Rule_revise::renderXhtml()
Renders a token into text matching the requested format.
Text_Wiki_Rule_freelink::renderXhtml()
Renders a token into text matching the requested format.
Text_Wiki_Rule_delimiter::renderXhtml()
Renders a token into text matching the requested format.
Text_Wiki_Rule_code::renderXhtml()
Renders a token into text matching the requested format.
Text_Wiki_Rule_horiz::renderXhtml()
Renders a token into text matching the requested format.
Text_Wiki_Rule_embed::renderXhtml()
Renders a token into text matching the requested format.
Text_Wiki_Rule_heading::renderXhtml()
Renders a token into text matching the requested format.
Text_Wiki_Rule_blockquote::renderXhtml()
Renders a token into text matching the requested format.

Parameters:

array   $options   —  The "options" portion of the token (second element).

[ Top ]

setToken   [line 213]

void setToken( int $id, [int $rule = null], [array $options = array()])

Set or re-set a token with specific information, overwriting any previous rule name and rule options.
  • Access: public

Parameters:

int   $id   —  The token number to reset.
int   $rule   —  The rule name to use; by default, use the current rule name, although you can specify any rule.
array   $options   —  An associative array of options for the token array element. The keys and values are specific to the rule, and may or may not be common to other rule options. Typical options keys are 'text' and 'type' but may include others.

[ Top ]


Documentation generated on Mon, 11 Mar 2019 10:14:15 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.