trfrm_func = array(); $this->stack = new Stack; } /** * Register transformation functions * * This should be done *before* calling do_transform * * @param $type enum
", * pre-formatted text "
", and the various list elements: * "
" element is not * allowed to contain any other block-level elements. Also
, *
");
}
// replace all URL's with tokens, so we don't confuse them
// with Wiki words later. Wiki words in URL's break things.
// URLs preceeded by a '!' are not linked
function wtt_urls($match, &$trfrm) {
return $match[0] == "!"
? substr($match,1)
: LinkURL($match);
}
// Link InterWiki links
// These can be protected by a '!' like Wiki words.
function wtt_interwikilinks($match, &$trfrm) {
if ($match[0] == '!')
return substr($match, 1);
global $request;
$map = InterWikiMap::GetMap($request);
return $map->link($match);
}
// Link Wiki words (BumpyText)
// Wikiwords preceeded by a '!' are not linked
function wtt_bumpylinks($match, &$trfrm) {
return $match[0] == "!" ? substr($match,1) : WikiLink($match, 'auto');
}
// Just quote the token.
function wtt_quotetoken($match, &$trfrm) {
return $match;
}
// end of tokenizer functions
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
// basic simple markup functions
// escape HTML metachars
function wtm_htmlchars($line, &$transformer) {
return XmlElement::_quote($line);
}
// %%% are linebreaks
function wtm_linebreak($line, &$transformer) {
return str_replace('%%%', '
', $line);
}
// bold and italics
function wtm_bold_italics($line, &$transformer) {
$line = preg_replace('|(__)(.*?)(__)|', '\2', $line);
$line = preg_replace("|('')(.*?)('')|", '\2', $line);
return $line;
}
//////////////////////////////////////////////////////////
// some tokens to be replaced by (dynamic) content
// FIXME: some plugins are in-line (maybe?) and some are block level.
// Here we treat them all as inline, which will probably
// generate some minorly invalid HTML in some cases.
//
function wtm_plugin_link($line, &$transformer) {
// FIXME: is this good syntax?
global $request; // FIXME: make these non-global?
if (preg_match('/^(.*?)(<\?plugin-link\s+.*?\?>)(.*)$/', $line, $m)) {
list(, $prematch, $plugin_pi, $postmatch) = $m;
$loader = new WikiPluginLoader;
$html = $loader->expandPI($plugin_pi, $request);
$line = $prematch . $transformer->token($html) . $postmatch;
}
return $line;
}
function wtm_plugin($line, &$transformer) {
// FIXME: is this good syntax?
global $request; // FIXME: make these non-global?
if (preg_match('/^<\?plugin(-form)?\s.*\?>\s*$/', $line)) {
$loader = new WikiPluginLoader;
$html = $loader->expandPI($line, $request);
$line = $transformer->SetHTMLMode('', 0) . $transformer->token($html);
}
return $line;
}
//////////////////////////////////////////////////////////
// mode markup functions
// tabless markup for unordered, ordered, and dictionary lists
// ul/ol list types can be mixed, so we only look at the last
// character. Changes e.g. from "**#*" to "###*" go unnoticed.
// and wouldn't make a difference to the HTML layout anyway.
// unordered lists
function wtm_preformatted($line, &$trfrm) { if (preg_match("/^\s+/", $line)) { $line = $trfrm->SetHTMLMode('pre') . $line; } return $line; } // mode: headings, i.e.,
,
// lines starting with !,!!,!!! are headings // Patch from steph/tara
: // use ,
,
since
is page title. function wtm_headings($line, &$trfrm) { if (preg_match("/^(!{1,3})[^!]/", $line, $whichheading)) { if($whichheading[1] == '!') $heading = 'h4'; elseif($whichheading[1] == '!!') $heading = 'h3'; elseif($whichheading[1] == '!!!') $heading = 'h2'; $line = preg_replace("/^!+/", '', $line); $line = $trfrm->SetHTMLMode($heading) . $line; } return $line; } // markup for tables function wtm_table($line, &$trfrm) { $row = ''; while (preg_match('/^(\|+)(v*)([<>^]?)([^|]*)/', $line, $m)) { $line = substr($line, strlen($m[0])); $td = HTML::td(); if (strlen($m[1]) > 1) $td->setAttr('colspan', strlen($m[1])); if (strlen($m[2]) > 0) $td->setAttr('rowspan', strlen($m[2]) + 1); if ($m[3] == '^') $td->setAttr('align', 'center'); else if ($m[3] == '>') $td->setAttr('align', 'right'); else $td->setAttr('align', 'left'); // FIXME: this is a hack: can't tokenize whole
since we // haven't marked up italics, etc... yet $row .= $trfrm->rawtoken($td->startTag() . " "); $row .= trim($m[4]); $row .= $trfrm->rawtoken(" " . $td->endTag()); } assert(empty($line)); $row = $trfrm->rawtoken(" ") . $row . $trfrm->rawtoken(" "); return $trfrm->SetHTMLMode(array('table', array('cellpadding' => 1, 'cellspacing' => 1, 'border' => 1))) . $row; } // four or more dashes to
// Note this is of type WT_MODE_MARKUP becuase
's aren't // allowed within's. (e.g. "
" is not valid HTML.) function wtm_hr($line, &$trfrm) { if (preg_match('/^-{4,}(.*)$/', $line, $m)) { $line = $trfrm->SetHTMLMode('', 0) . '
'; if ($m[1]) $line .= $trfrm->SetHTMLMode('p') . $m[1]; } return $line; } // default mode: simple text paragraph function wtm_paragraph($line, &$trfrm) { return $trfrm->SetHTMLMode('p') . $line; } // (c-file-style: "gnu") // Local Variables: // mode: php // tab-width: 8 // c-basic-offset: 4 // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: ?>