$html .= SetHTMLOutputMode('', ZERO_LEVEL, 0);
continue;
}
/* If your web server is not accessble to the general public, you may
allow this code below, which allows embedded HTML. If just anyone can reach
your web server it is highly advised that you do not allow this.
elseif (preg_match("/(^\|)(.*)/", $tmpline, $matches)) {
// HTML mode
$html .= SetHTMLOutputMode("", ZERO_LEVEL, 0);
$html .= $matches[2];
continue;
}
*/
//////////////////////////////////////////////////////////
// New linking scheme: links are in brackets. This will
// emulate typical HTML linking as well as Wiki linking.
// First need to protect [[.
$oldn = $ntokens;
$tmpline = tokenize($tmpline, '\[\[', $replacements, $ntokens);
while ($oldn < $ntokens)
$replacements[$oldn++] = '[';
// Now process the [\d+] links which are numeric references
$oldn = $ntokens;
$tmpline = tokenize($tmpline, '\[\s*\d+\s*\]', $replacements, $ntokens);
while ($oldn < $ntokens) {
$num = (int) substr($replacements[$oldn], 1);
if (! empty($embedded[$num]))
$replacements[$oldn] = $embedded[$num];
$oldn++;
}
// match anything else between brackets
$oldn = $ntokens;
$tmpline = tokenize($tmpline, '\[.+?\]', $replacements, $ntokens);
while ($oldn < $ntokens) {
$link = ParseAndLink($replacements[$oldn]);
$replacements[$oldn] = $link['link'];
$oldn++;
}
//////////////////////////////////////////////////////////
// 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
$tmpline = tokenize($tmpline, "!?\b($AllowedProtocols):[^\s<>\[\]\"'()]*[^\s<>\[\]\"'(),.?]", $replacements, $ntokens);
while ($oldn < $ntokens) {
if($replacements[$oldn][0] == '!')
$replacements[$oldn] = substr($replacements[$oldn], 1);
else
$replacements[$oldn] = LinkURL($replacements[$oldn]);
$oldn++;
}
//////////////////////////////////////////////////////////
// Link Wiki words
// Wikiwords preceeded by a '!' are not linked
$oldn = $ntokens;
$tmpline = tokenize($tmpline, "!?$WikiNameRegexp", $replacements, $ntokens);
while ($oldn < $ntokens) {
$old = $replacements[$oldn];
if ($old[0] == '!') {
$replacements[$oldn] = substr($old,1);
} elseif (IsWikiPage($dbi, $old)) {
$replacements[$oldn] = LinkExistingWikiWord($old);
} else {
$replacements[$oldn] = LinkUnknownWikiWord($old);
}
$oldn++;
}
//////////////////////////////////////////////////////////
// escape HTML metachars
$tmpline = str_replace('&', '&', $tmpline);
$tmpline = str_replace('>', '>', $tmpline);
$tmpline = str_replace('<', '<', $tmpline);
// %%% are linebreaks
$tmpline = str_replace('%%%', '
', $tmpline);
// bold italics (old way)
$tmpline = preg_replace("|(''''')(.*?)(''''')|",
"\\2", $tmpline);
// bold (old way)
$tmpline = preg_replace("|(''')(.*?)(''')|",
"\\2", $tmpline);
// bold
$tmpline = preg_replace("|(__)(.*?)(__)|",
"\\2", $tmpline);
// italics
$tmpline = preg_replace("|('')(.*?)('')|",
"\\2", $tmpline);
//////////////////////////////////////////////////////////
// unordered, ordered, and dictionary list (using TAB)
if (preg_match("/(^\t+)(.*?)(:\t)(.*$)/", $tmpline, $matches)) {
// this is a dictionary list (
$html .= SetHTMLOutputMode('pre', ZERO_LEVEL, 0); } elseif (preg_match("/^(!{1,3})[^!]/", $tmpline, $whichheading)) { // lines starting with !,!!,!!! are headings if($whichheading[1] == '!') $heading = 'h3'; elseif($whichheading[1] == '!!') $heading = 'h2'; elseif($whichheading[1] == '!!!') $heading = 'h1'; $tmpline = preg_replace("/^!+/", '', $tmpline); $html .= SetHTMLOutputMode($heading, ZERO_LEVEL, 0); } elseif (preg_match('/^-{4,}\s*(.*?)\s*$/', $tmpline, $matches)) { // four or more dashes to
//
can not be contained in a $html .= SetHTMLOutputMode('', ZERO_LEVEL, 0) . "
\n"; if ( ($tmpline = $matches[1]) != '' ) { $html .= SetHTMLOutputMode('p', ZERO_LEVEL, 0); } } else { // it's ordinary output if nothing else $html .= SetHTMLOutputMode('p', ZERO_LEVEL, 0); } // These are still problems as far as generating correct HTML is // concerned. Paragraph () elements are not allowed to contain // other block-level elements (like