Simplewiki
1.1
|
Parses wiki markup into tree of document nodes. More...
Public Member Functions | |
Property accessors | |
metadata () | |
Get metadata from parsed markup. | |
markerdata () | |
Get markerdata from parsed markup. | |
preprocessed_markup () | |
Get preprocessed markup, before parsing. | |
argchars ($argchars=NULL) | |
Get or set decorator argument character set (default '[^()]'). | |
Protected Attributes | |
Regular expression properties | |
$_rules holds the core rules combined into the applied regular expressions. The rest of these properties hold the applied regular expressions used by the dom creation (*_node) methods)
| |
$link_inline_re | |
Object that holds basic rules to be combined into applied regular expressions. | |
$image_inline_re | |
image inline parse | |
$item_inline_re | |
list inline item parse | |
$defitem_inline_re | |
definition inline item parse | |
$cell_re | |
quick table cell parse | |
$decorator_re | |
parse anything's decorator arguments | |
$tablerow_setaside_re | |
setaside for table row | |
$pre_escape_re | |
remove escape from pre | |
$_rules | |
object containing rules which combine into applied regular expressions | |
$block_re | |
block parse | |
$inline_re | |
inline parse | |
DOM control properties | |
$_curnode | |
the current node being processed | |
$_leaftextnode | |
the leaftextnode, which holds presentation text (no markup), and is alwasy of type SimpleWiki_DocNode::TEXT | |
$_root | |
the root document node | |
Data properties | |
$_raw | |
the original souce text to be processed | |
$_preprocessed_raw | |
the original souce text after preprocessing, but before parsing | |
$_argchars = '[^()]' | |
character set allowed for decorators (class names, properties and their values, attribuets and their values | |
$_metadata | |
metadata object possibly generated from first line of markup ("```## ...") | |
$_markerdata | |
from preprocessing, an object with textlength, markercount, markers | |
$_markers | |
Transient: from preprocessing, an array with marker objects, later folded into _markerdata. | |
Create Parser | |
__construct ($text) | |
Sets rules, sets regular expressions, and prepares any passed text. | |
_set_rules () | |
Set rules for parsing. | |
_set_re ($rules) | |
combine (set) the rules into applied regular expressions. | |
Parse control methods | |
prepare ($markup) | |
Prepares the text for processing. | |
parse () | |
Parse the prepared markup. | |
_parse_block ($raw) | |
Use the _block_re assembled regular expressions to parse the raw text for block structures. | |
_parse_inline ($raw) | |
Use the _inline_re assembled regular expressions to parse the raw text for inline structures. | |
_create_node ($preg_groups) | |
Directs parsed data from _parse_block and _parse_inline to the appropriate node creation method. | |
Setaside support | |
$_pre_markers = array() | |
markers to replace preformatted data | |
$_pre_markup = array() | |
preformatted element markup, matching markers | |
$_pre_count = 0 | |
count to include in generated preformatted marker identifier | |
$_tablerow_markers = array() | |
structure to set aside row contents before parsing row structure itself | |
$_tablerow_markup = array() | |
tablerow element markup, matching markers | |
$_tablerow_count = 0 | |
count to include in generated tablerow marker identifier | |
add_pre_and_code_markers ($preg_groups) | |
mark locations of preformatted data. | |
add_tablerow_markers ($preg_groups) | |
mark locations of tablerow data. | |
Parse support methods | |
get_decoration ($decorator_string) | |
gets common argument structure for decorators and block declarations. | |
get_selected_ancestor ($node, $types) | |
get the ancestor node of the passed node that has a type as listed in the second argument Look up the tree (starting with $node) to the first occurence of one of the listed types of nodes or root. | |
preprocess_raw_markup ($raw) | |
pre process the markup. | |
preprocess_markerdata ($matches) | |
preprocess marker data. | |
preprocess_metadata ($matches) | |
preprocess metadata. | |
set_node_decoration ($node, $decorator_string) | |
parse decorator and declaration arguments from string to structure into a node. | |
Dom creation methods | |
These methods are invoked by _create_node, based on the subgroup name of the first successful regular expression. The name is assembled with _<subgroupname>_node.
| |
_char_node ($preg_groups) | |
Character batch added to text stream. | |
_escape_node ($preg_groups) | |
Escaped character added to text stream. | |
_blankline_node ($preg_groups) | |
Triggers new block. | |
_paragraph_node ($preg_groups) | |
Creates paragraph node. | |
_heading_node ($preg_groups) | |
Creates heading node. | |
_emph_node ($preg_groups) | |
Create an emphasis node, or return from one. | |
_strong_node ($preg_groups) | |
Create a strong node, or return from one. | |
_linebreak_node ($preg_groups) | |
Create a linebreak node. | |
_horizontalrule_node ($preg_groups) | |
Create a horizontal rule node. | |
_link_node ($preg_groups) | |
Create a link node. | |
_image_node ($preg_groups) | |
Create an image node. | |
_list_node ($preg_groups) | |
Create a list node. | |
_item_node ($preg_groups) | |
Create a list item, and a list node if necessary. | |
_deflist_node ($preg_groups) | |
Create a definition list node. | |
_defitem_node ($preg_groups) | |
Create a definition term and description, and a definition list node if necessary. | |
_table_node ($preg_groups) | |
Process a quick table row. | |
_span_node ($preg_groups) | |
Create a span node. | |
_blockdivider_node ($preg_groups) | |
Block divider, a standalone decorator. | |
_code_node ($preg_groups) | |
Create an inline code node. | |
_pre_node ($preg_groups) | |
Create a block preformatted node. | |
_blockdef_node ($preg_groups) | |
Create a block node. | |
_macro_node ($preg_groups) | |
Create inline macro. | |
_blockmacro_node ($preg_groups) | |
Create block macro. | |
Debug functions | |
display_regex () | |
Display the regex assemblies. | |
display_dom ($root) | |
Display the dom. | |
display_dom_add_child ($node, &$childarray) | |
Support for display the dom. | |
Parses wiki markup into tree of document nodes.
Definition at line 31 of file parser.php.
__construct | ( | $text | ) |
Sets rules, sets regular expressions, and prepares any passed text.
string | $text | markup text to be parsed (can be NULL) |
Definition at line 87 of file parser.php.
|
protected |
Triggers new block.
This is done by resetting the current block to the nearest ancestor blockdef, or the root document.
array | $preg_groups | as returned by preg_replace_callback |
Definition at line 770 of file parser.php.
|
protected |
Create a block node.
SimpleWiki_DocNode::BLOCKDEF. Set reference to closest document, blockdef, list_item or def_desc ancestor. Create node, set decoration, parse inline portion and parse block portion.
Sets property $node->blocktag. Sets property $node->decoration.
array | $preg_groups | as returned by preg_replace_callback |
Definition at line 1353 of file parser.php.
|
protected |
Block divider, a standalone decorator.
SimpleWiki_DocNode::BLOCKDIVIDER.
|:b decoration:|
Sets property $node->decoration.
array | $preg_groups | as returned by preg_replace_callback |
Definition at line 1280 of file parser.php.
|
protected |
Create block macro.
SimpleWiki_DocNode::MACRO. The text portion is both saved as text and parsed.
Sets property $node->macroname. Sets property $node->textcontent if text is present. Sets property $node->decoration.
array | $preg_groups | as returned by preg_replace_callback |
Definition at line 1426 of file parser.php.
|
protected |
Character batch added to text stream.
Creates leaftextnode SimpleWiki_DocNode::TEXT if required. Creates a 'text' leaftextnode if none exists and adds the found characters to its content property.
Sets property $leaftextnode->textcontent.
array | $preg_groups | as returned by preg_replace_callback |
Definition at line 743 of file parser.php.
|
protected |
Create an inline code node.
SimpleWiki_DocNode::CODE.
Sets property $node->textcontent. Sets property $node->decoration.
array | $preg_groups | as returned by preg_replace_callback |
Definition at line 1297 of file parser.php.
|
protected |
Directs parsed data from _parse_block and _parse_inline to the appropriate node creation method.
Regular expressions are organized such that sucess results in assigning a string to the first subgroup name of the expression rule. The first subgroup name of the expression rule corresponds to the first part of the assembled name of the node creation method. This allows _create_node to search through the preg_groups for the first named array entry, and use that name to direct the preg_groups data to the method that can use the parsed data to create a dom element.
array | $preg_groups | taken from preg_replace_callback |
Definition at line 493 of file parser.php.
|
protected |
Create a definition term and description, and a definition list node if necessary.
SimpleWiki_DocNode::DEF_LIST, SimpleWiki_DocNode::DEF_TERM, SimpleWiki_DocNode::DEF_DESC.
Sets property $list->level. Sets property $list->decoration. Sets property $term->decoration. Sets property $desc->decoration.
array | $preg_groups | as returned by preg_replace_callback |
Definition at line 1088 of file parser.php.
|
protected |
Create a definition list node.
Parses the definition list markup as a whole, components to be processed by _item_node.
array | $preg_groups | as returned by preg_replace_callback |
Definition at line 1072 of file parser.php.
|
protected |
Create an emphasis node, or return from one.
SimpleWiki_DocNode::EMPHASIS.
If we are in an emphasis node, the emphasis markup denotes and end to the node. Otherwise a new emphasis node is created.
array | $preg_groups | as returned by preg_replace_callback |
Definition at line 864 of file parser.php.
|
protected |
Escaped character added to text stream.
Creates leaftextnode SimpleWiki_DocNode::TEXT if required. Creates a 'text' leaftextnode if none exists and adds the escaped character to its content property. The escape character itself is left behind.
Sets property $leaftextnode->textcontent.
array | $preg_groups | as returned by preg_replace_callback |
Definition at line 758 of file parser.php.
|
protected |
Creates heading node.
SimpleWiki_DocNode::HEADING. Changes current node to nearest block or document.
Creates a heading node, and does an inline parse of the heading text.
Sets property $node->level. Sets property $node->decoration.
array | $preg_groups | as returned by preg_replace_callback |
Definition at line 831 of file parser.php.
|
protected |
Create a horizontal rule node.
SimpleWiki_DocNode::HORIZONTALRULE. Moves to the nearest document or block ancestor, and creates a horizontalrule node.
array | $preg_groups | as returned by preg_replace_callback |
Definition at line 912 of file parser.php.
|
protected |
Create an image node.
SimpleWiki_DocNode::IMAGE. Parse the image text.
Sets property $node->target. Sets property $node->decoration.
array | $preg_groups | as returned by preg_replace_callback |
Definition at line 961 of file parser.php.
|
protected |
Create a list item, and a list node if necessary.
SimpleWiki_DocNode::ORDERED_LIST, SimpleWiki_DocNode::UNORDERED_LIST, SimpleWiki_DocNode::LIST_ITEM.
Sets property $list->level. Sets property $list->decoration. Sets property $item->decoration.
array | $preg_groups | as returned by preg_replace_callback |
Definition at line 1008 of file parser.php.
|
protected |
Create a linebreak node.
SimpleWiki_DocNode::LINEBREAK. Creates a linebreak node unconditionally.
array | $preg_groups | as returned by preg_replace_callback |
Definition at line 900 of file parser.php.
|
protected |
Create a link node.
SimpleWiki_DocNode::LINK. Parse the link text.
Sets property $node->target. Sets property $node->decoration.
array | $preg_groups | as returned by preg_replace_callback |
Definition at line 926 of file parser.php.
|
protected |
Create a list node.
Parses the list markup as a whole, components to be processed by _item_node.
array | $preg_groups | as returned by preg_replace_callback |
Definition at line 993 of file parser.php.
|
protected |
Create inline macro.
SimpleWiki_DocNode::MACRO. The text portion is both saved as text and parsed.
Sets property $node->macroname. Sets property $node->textcontent if text is present. Sets property $node->decoration.
array | $preg_groups | as returned by preg_replace_callback |
Definition at line 1392 of file parser.php.
|
protected |
Creates paragraph node.
SimpleWiki_DocNode::PARAGRAPH. If the current node is a table, table_row, or a list, then the current node is set to the nearest ancestor block or document.
If the current node is a block or document, a new paragraph node is created.
Then the paragraph is parsed for inline parsing.
Sets property $node->decoration.
array | $preg_groups | as returned by preg_replace_callback |
Definition at line 790 of file parser.php.
|
protected |
Use the _block_re assembled regular expressions to parse the raw text for block structures.
This method directs match processing to the _create_node controller, which then directs processing to the node creation method of the found (parsed) text
string | $raw | raw markup text |
Definition at line 463 of file parser.php.
|
protected |
Use the _inline_re assembled regular expressions to parse the raw text for inline structures.
This method directs match processing to the _create_node controller, which then directs processing to the node creation method of the found (parsed) text
string | $raw | raw markup text |
Definition at line 477 of file parser.php.
|
protected |
Create a block preformatted node.
SimpleWiki_DocNode::PREFORMATTED.
Sets property $node->textcontent. Sets property $node->decoration.
array | $preg_groups | as returned by preg_replace_callback |
Definition at line 1317 of file parser.php.
|
protected |
combine (set) the rules into applied regular expressions.
The following applied regular expressions are set by combining rules. See source code for details.
Definition at line 324 of file parser.php.
|
protected |
Set rules for parsing.
Creates a generic object, addes rules to it, and saves it to $this->_rules.
Rules are combined into applied regular expressions in _set_re.
The first subgroup name of each rule matches the first part of the node method name called by _create_node to create a dom node for the markup fragment.
char: characters except those that start inline markup: "/*\[{%<~" (emphasis, strong, linebreak, link, image/code, span, macro, escape), char is default expression for inline string.
blankline: empty line that separates blocks, especially paragraphs
paragraph: text not otherwise parsed with block parsing - handed over to inline parsing
headings: =*
emph: emphasis // there must be no ":" in front of the "//" or there must be whitespace after the forward slashes. This avoids italic rendering in urls with unknown protocols
strong: "**"
linebreak: "\\"
link: marked links: '[[...]]'
image: '{{...}}'
deflist: definition list ':* ... :: ... '. Matches the whole list, separate items are parsed later.
defitem: definition list item: Matches single list item. Isolates decorators, markup, term, and definition
list: ordered or unordered lists. Matches the whole list, separate items are parsed later. The list *must* start with a single bullet.
item: list item, matches single list item. Isolates decorators, markup, contents
table: simple tables, one line per row. table requires closing pipe
cell: break table row into cells. used for preg_match in table_node
escape: '~'
span: span decorator '% ... '. Empty decorator (optional) connotes end of span
blockdivider: '|:b ... :|' on line by itself.
code: '%c ...'
pre: block '{{{ ...'
pre_escape: allow ~ before closing included pre brace set (}}}). Simply removed.
blockdef: block declarations
macro: << ... >> inline
blockmacro: block version to prevent generation of <p> markup, allows surrounding whitespace
decorator: re to pull standard decorator structure: with or without operator; with or withoug '' or "" delimiters
Definition at line 104 of file parser.php.
|
protected |
Create a span node.
SimpleWiki_DocNode::SPAN. A span with a decorator opens a new span. An empty span (%%) closes an existing span, or is written as text if no span has been opened.
Sets property $leaftextnode->textcontent from markup with error. SimpleWiki_DocNode::TEXT. Sets property $node->decoration.
array | $preg_groups | as returned by preg_replace_callback |
Definition at line 1245 of file parser.php.
|
protected |
Create a strong node, or return from one.
SimpleWiki_DocNode::STRONG.
If we are in an strong node, the strong markup denotes and end to the node. Otherwise a new strong node is created.
array | $preg_groups | as returned by preg_replace_callback |
Definition at line 883 of file parser.php.
|
protected |
Process a quick table row.
Create a table node if necessary. SimpleWiki_DocNode::TABLE. Create a table row node. SimpleWiki_DocNode::TABLE_ROW. Create and parse cell nodes. SimpleWiki_DocNode::TABLE_HEADCELL, SimpleWiki_DocNode::TABLE_CELL.
Sets property $table->decoration. Sets property $row->decoration. Sets property $cell->decoration.
array | $preg_groups | as returned by preg_replace_callback |
Definition at line 1169 of file parser.php.
|
protected |
mark locations of preformatted data.
Set aside preformatted data, generate unique marker in the code for the data.
array | $preg_groups | as returned by preg_replace_callback |
Definition at line 530 of file parser.php.
|
protected |
mark locations of tablerow data.
set aside tablerow data
Set aside tablerow data, generate unique marker in the code for the data.
array | $preg_groups | as returned by preg_replace_callback |
Definition at line 553 of file parser.php.
argchars | ( | $argchars = NULL | ) |
Get or set decorator argument character set (default '[^()]').
string | $argchars | content of character set expression: $argchars |
Definition at line 404 of file parser.php.
display_dom | ( | $root | ) |
Display the dom.
Definition at line 1484 of file parser.php.
|
protected |
display_regex | ( | ) |
Display the regex assemblies.
Definition at line 1459 of file parser.php.
get_decoration | ( | $decorator_string | ) |
gets common argument structure for decorators and block declarations.
string | $decorator_string | the string found in decorators and block declarations |
Definition at line 658 of file parser.php.
get_selected_ancestor | ( | $node, | |
$types | |||
) |
get the ancestor node of the passed node that has a type as listed in the second argument Look up the tree (starting with $node) to the first occurence of one of the listed types of nodes or root.
If $node is in the list then the current node is returned.
object | $node | the node requesting the ancestor |
array | $types | the types of ancestors being requested |
Definition at line 718 of file parser.php.
markerdata | ( | ) |
Get markerdata from parsed markup.
Gets the markerdata from search of markers on the markup text.
The markerdata->markers array contains an object for each marker, with the properties string name, object decorator integer offset
Definition at line 387 of file parser.php.
metadata | ( | ) |
Get metadata from parsed markup.
Gets the metadata from the metadata section of the parsed markup.
Definition at line 376 of file parser.php.
parse | ( | ) |
Parse the prepared markup.
Parse preprocesses the raw markup, then calls the internal parse_block routine.
Definition at line 446 of file parser.php.
prepare | ( | $markup | ) |
Prepares the text for processing.
Creates node SimpleWiki_DocNode::DOCUMENT.
string | $markup | (markup text) |
This method creates the root document node (SimpleWiki_DocNode), and initializes the parser with the root node, the current node, and the leaftextnode.
Is called by constructor for any markup passed on creation, or can be called separately for iterative parsiong. $todo move preprocess_markup to prepare
Definition at line 431 of file parser.php.
|
protected |
preprocess marker data.
Find {{##markername markedecoration##}} markers, remove them, and collect data about them including offsets.
array | $matches | as returned from preg_replace_callback |
Definition at line 616 of file parser.php.
|
protected |
preprocess metadata.
Remove line continuation characters, and store metadata structure in _metadata property.
array | $matches | from preg_replace_callback |
Definition at line 645 of file parser.php.
|
protected |
pre process the markup.
string | $raw | source markup |
Definition at line 579 of file parser.php.
preprocessed_markup | ( | ) |
Get preprocessed markup, before parsing.
Preprocessed markup has metadata, comments, line coninuations, and markers removed.
Definition at line 396 of file parser.php.
|
protected |
parse decorator and declaration arguments from string to structure into a node.
object | $node | the node having the decoration |
string | $decorator_string | the pre-parsed string containing the argument data |
Definition at line 702 of file parser.php.
|
protected |
character set allowed for decorators (class names, properties and their values, attribuets and their values
Definition at line 70 of file parser.php.
|
protected |
the current node being processed
Definition at line 58 of file parser.php.
|
protected |
the leaftextnode, which holds presentation text (no markup), and is alwasy of type SimpleWiki_DocNode::TEXT
Definition at line 60 of file parser.php.
|
protected |
from preprocessing, an object with textlength, markercount, markers
Definition at line 75 of file parser.php.
|
protected |
Transient: from preprocessing, an array with marker objects, later folded into _markerdata.
Each marker object contains offset, name, decoration. Marker objects are indexed through integer in order, as well as by name index
Definition at line 79 of file parser.php.
|
protected |
metadata object possibly generated from first line of markup ("```## ...")
Definition at line 73 of file parser.php.
|
protected |
count to include in generated preformatted marker identifier
Definition at line 522 of file parser.php.
|
protected |
markers to replace preformatted data
Definition at line 518 of file parser.php.
|
protected |
preformatted element markup, matching markers
Definition at line 520 of file parser.php.
|
protected |
the original souce text after preprocessing, but before parsing
Definition at line 68 of file parser.php.
|
protected |
the original souce text to be processed
Definition at line 66 of file parser.php.
|
protected |
the root document node
Definition at line 62 of file parser.php.
|
protected |
object containing rules which combine into applied regular expressions
Definition at line 51 of file parser.php.
|
protected |
count to include in generated tablerow marker identifier
Definition at line 546 of file parser.php.
|
protected |
structure to set aside row contents before parsing row structure itself
Definition at line 542 of file parser.php.
|
protected |
tablerow element markup, matching markers
Definition at line 544 of file parser.php.
|
protected |
block parse
Definition at line 52 of file parser.php.
|
protected |
quick table cell parse
Definition at line 47 of file parser.php.
|
protected |
parse anything's decorator arguments
Definition at line 48 of file parser.php.
|
protected |
definition inline item parse
Definition at line 46 of file parser.php.
|
protected |
image inline parse
Definition at line 44 of file parser.php.
|
protected |
inline parse
Definition at line 53 of file parser.php.
|
protected |
list inline item parse
Definition at line 45 of file parser.php.
|
protected |
Object that holds basic rules to be combined into applied regular expressions.
Definition at line 43 of file parser.php.
|
protected |
remove escape from pre
Definition at line 50 of file parser.php.
|
protected |
setaside for table row
Definition at line 49 of file parser.php.