1 <?php rcs_id('$Id: BlockParser.php,v 1.52 2004-10-21 19:52:10 rurban Exp $');
2 /* Copyright (C) 2002, Geoffrey T. Dairiki <dairiki@dairiki.org>
4 * This file is part of PhpWiki.
6 * PhpWiki is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * PhpWiki is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with PhpWiki; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 require_once('lib/HtmlElement.php');
21 require_once('lib/CachedMarkup.php');
22 require_once('lib/InlineParser.php');
24 ////////////////////////////////////////////////////////////////
29 * Deal with paragraphs and proper, recursive block indents
30 * for the new style markup (version 2)
32 * Everything which goes over more than line:
33 * automatic lists, UL, OL, DL, table, blockquote, verbatim,
39 * FIXME: unify this with the RegexpSet in InlineParser.
41 * FIXME: This is very php5 sensitive: It was fixed for 1.3.9,
42 * but is again broken with the 1.3.11
43 * allow_call_time_pass_reference clean fixes
46 * @author: Geoffrey T. Dairiki
50 * Return type from RegexpSet::match and RegexpSet::nextMatch.
54 class AnchoredRegexpSet_match {
61 * The text following the matched text.
66 * Index of the regular expression which matched.
72 * A set of regular expressions.
74 * This class is probably only useful for InlineTransformer.
76 class AnchoredRegexpSet
80 * @param $regexps array A list of regular expressions. The
81 * regular expressions should not include any sub-pattern groups
82 * "(...)". (Anonymous groups, like "(?:...)", as well as
83 * look-ahead and look-behind assertions are fine.)
85 function AnchoredRegexpSet ($regexps) {
86 $this->_regexps = $regexps;
87 $this->_re = "/((" . join(")|(", $regexps) . "))/Ax";
91 * Search text for the next matching regexp from the Regexp Set.
93 * @param $text string The text to search.
95 * @return object A RegexpSet_match object, or false if no match.
97 function match ($text) {
98 if (!is_string($text)) return false;
99 if (! preg_match($this->_re, $text, $m)) {
103 $match = new AnchoredRegexpSet_match;
104 $match->postmatch = substr($text, strlen($m[0]));
105 $match->match = $m[1];
106 $match->regexp_ind = count($m) - 3;
111 * Search for next matching regexp.
113 * Here, 'next' has two meanings:
115 * Match the next regexp(s) in the set, at the same position as the last match.
117 * If that fails, match the whole RegexpSet, starting after the position of the
120 * @param $text string Text to search.
122 * @param $prevMatch A RegexpSet_match object
124 * $prevMatch should be a match object obtained by a previous
125 * match upon the same value of $text.
127 * @return object A RegexpSet_match object, or false if no match.
129 function nextMatch ($text, $prevMatch) {
130 // Try to find match at same position.
131 $regexps = array_slice($this->_regexps, $prevMatch->regexp_ind + 1);
136 $pat= "/ ( (" . join(')|(', $regexps) . ") ) /Axs";
138 if (! preg_match($pat, $text, $m)) {
142 $match = new AnchoredRegexpSet_match;
143 $match->postmatch = substr($text, strlen($m[0]));
144 $match->match = $m[1];
145 $match->regexp_ind = count($m) - 3 + $prevMatch->regexp_ind + 1;;
152 class BlockParser_Input {
154 function BlockParser_Input ($text) {
156 // Expand leading tabs.
157 // FIXME: do this better.
159 // We want to ensure the only characters matching \s are ' ' and "\n".
161 $text = preg_replace('/(?![ \n])\s/', ' ', $text);
162 assert(!preg_match('/(?![ \n])\s/', $text));
164 $this->_lines = preg_split('/[^\S\n]*\n/', $text);
167 // Strip leading blank lines.
168 while ($this->_lines and ! $this->_lines[0])
169 array_shift($this->_lines);
170 $this->_atSpace = false;
173 function skipSpace () {
174 $nlines = count($this->_lines);
176 if ($this->_pos >= $nlines) {
177 $this->_atSpace = false;
180 if ($this->_lines[$this->_pos] != '')
183 $this->_atSpace = true;
185 return $this->_atSpace;
188 function currentLine () {
189 if ($this->_pos >= count($this->_lines)) {
192 return $this->_lines[$this->_pos];
195 function nextLine () {
196 $this->_atSpace = $this->_lines[$this->_pos++] === '';
197 if ($this->_pos >= count($this->_lines)) {
200 return $this->_lines[$this->_pos];
203 function advance () {
204 $this->_atSpace = $this->_lines[$this->_pos++] === '';
208 return array($this->_pos, $this->_atSpace);
211 function setPos ($pos) {
212 list($this->_pos, $this->_atSpace) = $pos;
215 function getPrefix () {
219 function getDepth () {
224 if ($this->_pos < count($this->_lines))
225 return $this->_lines[$this->_pos];
230 function _debug ($tab, $msg) {
232 $where = $this->where();
233 $tab = str_repeat('____', $this->getDepth() ) . $tab;
234 printXML(HTML::div("$tab $msg: at: '",
241 class BlockParser_InputSubBlock extends BlockParser_Input
243 function BlockParser_InputSubBlock (&$input, $prefix_re, $initial_prefix = false) {
244 $this->_input = &$input;
245 $this->_prefix_pat = "/$prefix_re|\\s*\$/Ax";
246 $this->_atSpace = false;
248 if (($line = $input->currentLine()) === false)
249 $this->_line = false;
250 elseif ($initial_prefix) {
251 assert(substr($line, 0, strlen($initial_prefix)) == $initial_prefix);
252 $this->_line = (string) substr($line, strlen($initial_prefix));
253 $this->_atBlank = ! ltrim($line);
255 elseif (preg_match($this->_prefix_pat, $line, $m)) {
256 $this->_line = (string) substr($line, strlen($m[0]));
257 $this->_atBlank = ! ltrim($line);
260 $this->_line = false;
263 function skipSpace () {
264 // In contrast to the case for top-level blocks,
265 // for sub-blocks, there never appears to be any trailing space.
266 // (The last block in the sub-block should always be of class tight-bottom.)
267 while ($this->_line === '')
270 if ($this->_line === false)
271 return $this->_atSpace == 'strong_space';
273 return $this->_atSpace;
276 function currentLine () {
280 function nextLine () {
281 if ($this->_line === '')
282 $this->_atSpace = $this->_atBlank ? 'weak_space' : 'strong_space';
284 $this->_atSpace = false;
286 $line = $this->_input->nextLine();
287 if ($line !== false && preg_match($this->_prefix_pat, $line, $m)) {
288 $this->_line = (string) substr($line, strlen($m[0]));
289 $this->_atBlank = ! ltrim($line);
292 $this->_line = false;
297 function advance () {
302 return array($this->_line, $this->_atSpace, $this->_input->getPos());
305 function setPos ($pos) {
306 $this->_line = $pos[0];
307 $this->_atSpace = $pos[1];
308 $this->_input->setPos($pos[2]);
311 function getPrefix () {
312 assert ($this->_line !== false);
313 $line = $this->_input->currentLine();
314 assert ($line !== false && strlen($line) >= strlen($this->_line));
315 return substr($line, 0, strlen($line) - strlen($this->_line));
318 function getDepth () {
319 return $this->_input->getDepth() + 1;
323 return $this->_input->where();
328 class Block_HtmlElement extends HtmlElement
330 function Block_HtmlElement($tag /*, ... */) {
331 $this->_init(func_get_args());
334 function setTightness($top, $bottom) {
335 $this->setInClass('tightenable');
336 $this->setInClass('top', $top);
337 $this->setInClass('bottom', $bottom);
341 class ParsedBlock extends Block_HtmlElement {
343 function ParsedBlock (&$input, $tag = 'div', $attr = false) {
344 $this->Block_HtmlElement($tag, $attr);
345 $this->_initBlockTypes();
346 $this->_parse($input);
349 function _parse (&$input) {
350 for ($block = $this->_getBlock($input); $block; $block = $nextBlock) {
351 while ($nextBlock = $this->_getBlock($input)) {
352 // Attempt to merge current with following block.
353 if (! ($merged = $block->merge($nextBlock)) ) {
354 break; // can't merge
358 $this->pushContent($block->finish());
362 // FIXME: hackish. This should only be called once.
363 function _initBlockTypes () {
364 // better static or global?
365 static $_regexpset, $_block_types;
367 if (!is_object($_regexpset)) {
368 foreach (array('oldlists', 'list', 'dl', 'table_dl',
369 'blockquote', 'heading', 'hr', 'pre', 'email_blockquote',
372 $class = "Block_$type";
374 $this->_block_types[] = $proto;
375 $this->_regexps[] = $proto->_re;
377 $this->_regexpset = new AnchoredRegexpSet($this->_regexps);
378 $_regexpset = $this->_regexpset;
379 $_block_types = $this->_block_types;
381 $this->_regexpset = $_regexpset;
382 $this->_block_types = $_block_types;
386 function _getBlock (&$input) {
387 $this->_atSpace = $input->skipSpace();
389 $line = $input->currentLine();
390 if ($line === false or $line === '') { // allow $line === '0'
393 $tight_top = !$this->_atSpace;
394 $re_set = &$this->_regexpset;
395 for ($m = $re_set->match($line); $m; $m = $re_set->nextMatch($line, $m)) {
396 $block = $this->_block_types[$m->regexp_ind];
397 if (DEBUG & _DEBUG_PARSER)
398 $input->_debug('>', get_class($block));
400 if ($block->_match($input, $m)) {
401 if (DEBUG & _DEBUG_PARSER)
402 $input->_debug('<', get_class($block));
403 $tight_bottom = ! $input->skipSpace();
404 $block->_setTightness($tight_top, $tight_bottom);
407 if (DEBUG & _DEBUG_PARSER)
408 $input->_debug('[', "_match failed");
410 if ($line === false or $line === '') // allow $line === '0'
413 trigger_error("Couldn't match block: '$line'", E_USER_NOTICE);
418 class WikiText extends ParsedBlock {
419 function WikiText ($text) {
420 $input = new BlockParser_Input($text);
421 $this->ParsedBlock($input);
425 class SubBlock extends ParsedBlock {
426 function SubBlock (&$input, $indent_re, $initial_indent = false,
427 $tag = 'div', $attr = false) {
428 $subinput = new BlockParser_InputSubBlock($input, $indent_re, $initial_indent);
429 $this->ParsedBlock($subinput, $tag, $attr);
434 * TightSubBlock is for use in parsing lists item bodies.
436 * If the sub-block consists of a single paragraph, it omits
437 * the paragraph element.
439 * We go to this trouble so that "tight" lists look somewhat reasonable
440 * in older (non-CSS) browsers. (If you don't do this, then, without
441 * CSS, you only get "loose" lists.
443 class TightSubBlock extends SubBlock {
444 function TightSubBlock (&$input, $indent_re, $initial_indent = false,
445 $tag = 'div', $attr = false) {
446 $this->SubBlock($input, $indent_re, $initial_indent, $tag, $attr);
448 // If content is a single paragraph, eliminate the paragraph...
449 if (count($this->_content) == 1) {
450 $elem = $this->_content[0];
451 if (isa($elem, 'XmlElement') and $elem->getTag() == 'p') {
452 assert($elem->getAttr('class') == 'tightenable top bottom');
453 $this->setContent($elem->getContent());
462 function _match (&$input, $match) {
463 trigger_error('pure virtual', E_USER_ERROR);
466 function _setTightness ($top, $bot) {
467 $this->_element->setTightness($top, $bot);
470 function merge ($followingBlock) {
475 return $this->_element;
479 class Block_blockquote extends BlockMarkup
483 var $_re = '\ +(?=\S)';
485 function _match (&$input, $m) {
486 $this->_depth = strlen($m->match);
487 $indent = sprintf("\\ {%d}", $this->_depth);
488 $this->_element = new SubBlock($input, $indent, $m->match,
493 function merge ($nextBlock) {
494 if (get_class($nextBlock) == get_class($this)) {
495 assert ($nextBlock->_depth < $this->_depth);
496 $nextBlock->_element->unshiftContent($this->_element);
497 $nextBlock->_tight_top = $this->_tight_top;
504 class Block_list extends BlockMarkup
506 //var $_tag = 'ol' or 'ul';
512 | [*] (?!(?=\S)[^*]*(?<=\S)[*](?:\\s|[-)}>"\'\\/:.,;!?_*=]) )
515 var $_content = array();
517 function _match (&$input, $m) {
518 // A list as the first content in a list is not allowed.
521 // Should markup as <ul><li>* Item</li></ul>,
522 // not <ul><li><ul><li>Item</li></ul>/li></ul>.
524 if (preg_match('/[*#+-o]/', $input->getPrefix())) {
529 $indent = sprintf("\\ {%d}", strlen($prefix));
531 $bullet = trim($m->match);
532 $this->_tag = $bullet == '#' ? 'ol' : 'ul';
533 $this->_content[] = new TightSubBlock($input, $indent, $m->match, 'li');
537 function _setTightness($top, $bot) {
538 $li = &$this->_content[0];
539 $li->setTightness($top, $bot);
542 function merge ($nextBlock) {
543 if (isa($nextBlock, 'Block_list') and $this->_tag == $nextBlock->_tag) {
544 if ($nextBlock->_content === $this->_content) {
545 trigger_error("Internal Error: no block advance", E_USER_NOTICE);
548 array_splice($this->_content, count($this->_content), 0,
549 $nextBlock->_content);
556 return new Block_HtmlElement($this->_tag, false, $this->_content);
560 class Block_dl extends Block_list
564 function Block_dl () {
565 $this->_re = '\ {0,4}\S.*(?<!'.ESCAPE_CHAR.'):\s*$';
568 function _match (&$input, $m) {
569 if (!($p = $this->_do_match($input, $m)))
571 list ($term, $defn, $loose) = $p;
573 $this->_content[] = new Block_HtmlElement('dt', false, $term);
574 $this->_content[] = $defn;
575 $this->_tight_defn = !$loose;
579 function _setTightness($top, $bot) {
580 $dt = &$this->_content[0];
581 $dd = &$this->_content[1];
583 $dt->setTightness($top, $this->_tight_defn);
584 $dd->setTightness($this->_tight_defn, $bot);
587 function _do_match (&$input, $m) {
588 $pos = $input->getPos();
590 $firstIndent = strspn($m->match, ' ');
591 $pat = sprintf('/\ {%d,%d}(?=\s*\S)/A', $firstIndent + 1, $firstIndent + 5);
594 $loose = $input->skipSpace();
595 $line = $input->currentLine();
597 if (!$line || !preg_match($pat, $line, $mm)) {
598 $input->setPos($pos);
599 return false; // No body found.
602 $indent = strlen($mm[0]);
603 $term = TransformInline(rtrim(substr(trim($m->match),0,-1)));
604 $defn = new TightSubBlock($input, sprintf("\\ {%d}", $indent), false, 'dd');
605 return array($term, $defn, $loose);
611 class Block_table_dl_defn extends XmlContent
616 function Block_table_dl_defn ($term, $defn) {
618 if (!is_array($defn))
619 $defn = $defn->getContent();
621 $this->_next_tight_top = false; // value irrelevant - gets fixed later
622 $this->_ncols = $this->_ComputeNcols($defn);
625 foreach ($defn as $item) {
626 if ($this->_IsASubtable($item))
627 $this->_addSubtable($item);
629 $this->_addToRow($item);
633 $th = HTML::th($term);
634 if ($this->_nrows > 1)
635 $th->setAttr('rowspan', $this->_nrows);
636 $this->_setTerm($th);
639 function setTightness($tight_top, $tight_bot) {
640 $this->_tight_top = $tight_top;
641 $this->_tight_bot = $tight_bot;
642 $first = &$this->firstTR();
643 $last = &$this->lastTR();
644 $first->setInClass('top', $tight_top);
646 $last->setInClass('bottom', $tight_bot);
648 trigger_error(sprintf("no lastTR: %s",AsXML($this->_content[0])), E_USER_WARNING);
652 function _addToRow ($item) {
653 if (empty($this->_accum)) {
654 $this->_accum = HTML::td();
655 if ($this->_ncols > 2)
656 $this->_accum->setAttr('colspan', $this->_ncols - 1);
658 $this->_accum->pushContent($item);
661 function _flushRow ($tight_bottom=false) {
662 if (!empty($this->_accum)) {
663 $row = new Block_HtmlElement('tr', false, $this->_accum);
665 $row->setTightness($this->_next_tight_top, $tight_bottom);
666 $this->_next_tight_top = $tight_bottom;
668 $this->pushContent($row);
669 $this->_accum = false;
674 function _addSubtable ($table) {
675 if (!($table_rows = $table->getContent()))
678 $this->_flushRow($table_rows[0]->_tight_top);
680 foreach ($table_rows as $subdef) {
681 $this->pushContent($subdef);
682 $this->_nrows += $subdef->nrows();
683 $this->_next_tight_top = $subdef->_tight_bot;
687 function _setTerm ($th) {
688 $first_row = &$this->_content[0];
689 if (isa($first_row, 'Block_table_dl_defn'))
690 $first_row->_setTerm($th);
692 $first_row->unshiftContent($th);
695 function _ComputeNcols ($defn) {
697 foreach ($defn as $item) {
698 if ($this->_IsASubtable($item)) {
699 $row = $this->_FirstDefn($item);
700 $ncols = max($ncols, $row->ncols() + 1);
706 function _IsASubtable ($item) {
707 return isa($item, 'HtmlElement')
708 && $item->getTag() == 'table'
709 && $item->getAttr('class') == 'wiki-dl-table';
712 function _FirstDefn ($subtable) {
713 $defs = $subtable->getContent();
718 return $this->_ncols;
722 return $this->_nrows;
725 function & firstTR() {
726 $first = &$this->_content[0];
727 if (isa($first, 'Block_table_dl_defn'))
728 return $first->firstTR();
732 function & lastTR() {
733 $last = &$this->_content[$this->_nrows - 1];
734 if (isa($last, 'Block_table_dl_defn'))
735 return $last->lastTR();
739 function setWidth ($ncols) {
740 assert($ncols >= $this->_ncols);
741 if ($ncols <= $this->_ncols)
743 $rows = &$this->_content;
744 for ($i = 0; $i < count($rows); $i++) {
746 if (isa($row, 'Block_table_dl_defn'))
747 $row->setWidth($ncols - 1);
749 $n = count($row->_content);
750 $lastcol = &$row->_content[$n - 1];
751 if (!empty($lastcol))
752 $lastcol->setAttr('colspan', $ncols - 1);
758 class Block_table_dl extends Block_dl
760 var $_tag = 'dl-table'; // phony.
762 function Block_table_dl() {
763 $this->_re = '\ {0,4} (?:\S.*)? (?<!'.ESCAPE_CHAR.') \| \s* $';
766 function _match (&$input, $m) {
767 if (!($p = $this->_do_match($input, $m)))
769 list ($term, $defn, $loose) = $p;
771 $this->_content[] = new Block_table_dl_defn($term, $defn);
775 function _setTightness($top, $bot) {
776 $this->_content[0]->setTightness($top, $bot);
781 $defs = &$this->_content;
784 foreach ($defs as $defn)
785 $ncols = max($ncols, $defn->ncols());
787 foreach ($defs as $key => $defn)
788 $defs[$key]->setWidth($ncols);
790 return HTML::table(array('class' => 'wiki-dl-table',
798 class Block_oldlists extends Block_list
800 //var $_tag = 'ol', 'ul', or 'dl';
801 var $_re = '(?: [*] (?!(?=\S)[^*]*(?<=\S)[*](?:\\s|[-)}>"\'\\/:.,;!?_*=]))
802 | [#] (?! \[ .*? \] )
806 function _match (&$input, $m) {
808 if (!preg_match('/[*#;]*$/A', $input->getPrefix())) {
814 $oldindent = '[*#;](?=[#*]|;.*:.*\S)';
815 $newindent = sprintf('\\ {%d}', strlen($prefix));
816 $indent = "(?:$oldindent|$newindent)";
818 $bullet = $prefix[0];
819 if ($bullet == '*') {
823 elseif ($bullet == '#') {
829 list ($term,) = explode(':', substr($prefix, 1), 2);
832 $this->_content[] = new Block_HtmlElement('dt', false,
833 TransformInline($term));
837 $this->_content[] = new TightSubBlock($input, $indent, $m->match, $itemtag);
841 function _setTightness($top, $bot) {
842 if (count($this->_content) == 1) {
843 $li = &$this->_content[0];
844 $li->setTightness($top, $bot);
847 // This is where php5 usually brakes.
848 // wrong duplicated <li> contents
849 if (DEBUG and DEBUG & _DEBUG_PARSER and check_php_version(5)) {
850 if (count($this->_content) != 2) {
853 $class = new Reflection_Class('XmlElement');
854 // Print out basic information
856 "===> The %s%s%s %s '%s' [extends %s]\n".
859 " having the modifiers %d [%s]\n",
860 $class->isInternal() ? 'internal' : 'user-defined',
861 $class->isAbstract() ? ' abstract' : '',
862 $class->isFinal() ? ' final' : '',
863 $class->isInterface() ? 'interface' : 'class',
865 var_export($class->getParentClass(), 1),
866 $class->getFileName(),
867 $class->getStartLine(),
868 $class->getEndline(),
869 $class->getModifiers(),
870 implode(' ', Reflection::getModifierNames($class->getModifiers()))
872 // Print class properties
873 printf("---> Properties: %s\n", var_export($class->getProperties(), 1));
875 echo 'count($this->_content): ', count($this->_content),"\n";
876 echo "\$this->_content[0]: "; var_dump ($this->_content[0]);
878 for ($i=1; $i < min(5, count($this->_content)); $i++) {
879 $c =& $this->_content[$i];
880 echo '$this->_content[',$i,"]: \n";
881 echo "_tag: "; var_dump ($c->_tag);
882 echo "_content: "; var_dump ($c->_content);
883 echo "_properties: "; var_dump ($c->_properties);
885 debug_print_backtrace();
886 if (DEBUG & _DEBUG_APD) {
887 if (function_exists("xdebug_get_function_stack")) {
888 var_dump (xdebug_get_function_stack());
894 if (!check_php_version(5))
895 assert(count($this->_content) == 2);
896 $dt = &$this->_content[0];
897 $dd = &$this->_content[1];
898 $dt->setTightness($top, false);
899 $dd->setTightness(false, $bot);
904 class Block_pre extends BlockMarkup
906 var $_re = '<(?:pre|verbatim)>';
908 function _match (&$input, $m) {
909 $endtag = '</' . substr($m->match, 1);
911 $pos = $input->getPos();
913 $line = $m->postmatch;
914 while (ltrim($line) != $endtag) {
916 if (($line = $input->nextLine()) === false) {
917 $input->setPos($pos);
923 $text = join("\n", $text);
925 // FIXME: no <img>, <big>, <small>, <sup>, or <sub>'s allowed
927 if ($m->match == '<pre>')
928 $text = TransformInline($text);
930 $this->_element = new Block_HtmlElement('pre', false, $text);
936 class Block_plugin extends Block_pre
938 var $_re = '<\?plugin(?:-form)?(?!\S)';
941 /* <?plugin Backlinks
943 /* <?plugin ListPages pages=<!plugin-list Backlinks!>
944 * exclude=<!plugin-list TitleSearch s=T*!> ?>
948 function _match (&$input, $m) {
949 $pos = $input->getPos();
950 $pi = $m->match . $m->postmatch;
951 while (!preg_match('/(?<!'.ESCAPE_CHAR.')\?>\s*$/', $pi)) {
952 if (($line = $input->nextLine()) === false) {
953 $input->setPos($pos);
960 $this->_element = new Cached_PluginInvocation($pi);
965 class Block_email_blockquote extends BlockMarkup
967 var $_attr = array('class' => 'mail-style-quote');
970 function _match (&$input, $m) {
971 //$indent = str_replace(' ', '\\ ', $m->match) . '|>$';
972 $indent = $this->_re;
973 $this->_element = new SubBlock($input, $indent, $m->match,
974 'blockquote', $this->_attr);
979 class Block_hr extends BlockMarkup
981 var $_re = '-{4,}\s*$';
983 function _match (&$input, $m) {
985 $this->_element = new Block_HtmlElement('hr');
989 function _setTightness($top, $bot) {
990 // Don't tighten <hr/>s
994 class Block_heading extends BlockMarkup
998 function _match (&$input, $m) {
999 $tag = "h" . (5 - strlen($m->match));
1000 $text = TransformInline(trim($m->postmatch));
1003 $this->_element = new Block_HtmlElement($tag, false, $text);
1008 function _setTightness($top, $bot) {
1009 // Don't tighten headers.
1013 class Block_p extends BlockMarkup
1018 function _match (&$input, $m) {
1019 $this->_text = $m->match;
1024 function _setTightness ($top, $bot) {
1025 $this->_tight_top = $top;
1026 $this->_tight_bot = $bot;
1029 function merge ($nextBlock) {
1030 $class = get_class($nextBlock);
1031 if (strtolower($class) == 'block_p' and $this->_tight_bot) {
1032 $this->_text .= "\n" . $nextBlock->_text;
1033 $this->_tight_bot = $nextBlock->_tight_bot;
1039 function finish () {
1040 $content = TransformInline(trim($this->_text));
1041 $p = new Block_HtmlElement('p', false, $content);
1042 $p->setTightness($this->_tight_top, $this->_tight_bot);
1047 ////////////////////////////////////////////////////////////////
1051 * Transform the text of a page, and return a parse tree.
1053 function TransformTextPre ($text, $markup = 2.0, $basepage=false) {
1054 if (isa($text, 'WikiDB_PageRevision')) {
1056 $text = $rev->getPackedContent();
1057 $markup = $rev->get('markup');
1059 // NEW: default markup is new, to increase stability
1060 if (!empty($markup) && $markup < 2.0) {
1061 $text = ConvertOldMarkup($text);
1064 // Expand leading tabs.
1065 $text = expand_tabs($text);
1066 //set_time_limit(3);
1067 $output = new WikiText($text);
1069 /* if (0 and DEBUG and DEBUG & _DEBUG_VERBOSE and check_php_version(5)) {
1070 echo "<pre>"; var_dump($output); echo "</pre>";
1076 * Transform the text of a page, and return an XmlContent,
1077 * suitable for printXml()-ing.
1079 function TransformText ($text, $markup = 2.0, $basepage=false) {
1080 $output = TransformTextPre($text, $markup, $basepage);
1082 // This is for immediate consumption.
1083 // We must bind the contents to a base pagename so that
1084 // relative page links can be properly linkified...
1085 return new CacheableMarkup($output->getContent(), $basepage);
1087 return new XmlContent($output->getContent());
1090 // $Log: not supported by cvs2svn $
1091 // Revision 1.51 2004/09/14 09:54:04 rurban
1092 // cache ParsedBlock::_initBlockTypes
1094 // Revision 1.50 2004/09/08 13:38:00 rurban
1095 // improve loadfile stability by using markup=2 as default for undefined markup-style.
1096 // use more refs for huge objects.
1097 // fix debug=static issue in WikiPluginCached
1099 // Revision 1.49 2004/07/02 09:55:58 rurban
1100 // more stability fixes: new DISABLE_GETIMAGESIZE if your php crashes when loading LinkIcons: failing getimagesize in old phps; blockparser stabilized
1102 // Revision 1.48 2004/06/21 06:30:16 rurban
1103 // revert to prev references
1105 // Revision 1.47 2004/06/20 15:30:04 rurban
1106 // get_class case-sensitivity issues
1108 // Revision 1.46 2004/06/20 14:42:53 rurban
1109 // various php5 fixes (still broken at blockparser)
1112 // (c-file-style: "gnu")
1116 // c-basic-offset: 4
1117 // c-hanging-comment-ender-p: nil
1118 // indent-tabs-mode: nil