_transformer_tags = false; } function Head($name = 'edit[content]') { trigger_error("virtual", E_USER_ERROR); } // to be called after function Textarea($textarea, $wikitext, $name = 'edit[content]') { trigger_error("virtual", E_USER_ERROR); } /** * Handler to convert the Wiki Markup to HTML before editing. * This will be converted back by WysiwygEdit_ConvertAfter if required. * *text* => 'text' */ function ConvertBefore($text) { require_once 'lib/BlockParser.php'; $xml = TransformText($text, $GLOBALS['request']->getArg('pagename')); return $xml->AsXML(); } /** * FIXME: Handler to convert the HTML formatting back to wiki formatting. * Derived from InlineParser, but returning wiki text instead of HtmlElement objects. * 'text' => 'text' => '*text*' * * TODO: Switch over to HtmlParser */ function ConvertAfter($text) { static $trfm; if (empty($trfm)) { $trfm = new HtmlTransformer($this->_transformer_tags); } $markup = $trfm->parse($text); // version 2.0 return $markup; } } // re-use these classes for the regexp's. // just output strings instead of XmlObjects class Markup_html_br extends Markup_linebreak { function markup($match) { return $match; } } class Markup_html_simple_tag extends Markup_html_emphasis { function markup($match, $body) { $tag = substr($match, 1, -1); switch ($tag) { case 'b': case 'strong': return "*" . $body . "*"; case 'big': return "" . $body . ""; case 'i': case 'em': return "_" . $body . "_"; } } } class Markup_html_p extends BalancedMarkup { public $_start_regexp = "<(?:p|P)( class=\".*\")?>"; function getEndRegexp($match) { return "<\\/" . substr($match, 1); } function markup($match, $body) { return $body . "\n"; } } //'text' => '*text*' class Markup_html_spanbold extends BalancedMarkup { public $_start_regexp = "<(?:span|SPAN) style=\"FONT-WEIGHT: bold\">"; function getEndRegexp($match) { return "<\\/" . substr($match, 1); } function markup($match, $body) { //Todo: convert style formatting to simplier nested tags return "*" . $body . "*"; } } class HtmlTransformer extends InlineTransformer { function HtmlTransformer($tags = false) { if (!$tags) $tags = array('escape', 'html_br', 'html_spanbold', 'html_simple_tag', 'html_p',); /* 'html_a','html_span','html_div', 'html_table','html_hr','html_pre', 'html_blockquote', 'html_indent','html_ol','html_li','html_ul','html_img' */ return $this->InlineTransformer($tags); } } // Local Variables: // mode: php // tab-width: 8 // c-basic-offset: 4 // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: