--- /var/www/localhost/htdocs/drupal/modules/wiki/wiki.module 2005-05-14 23:37:41.000000000 +0200 +++ wiki.module 2005-08-23 09:49:25.000000000 +0200 @@ -1,6 +1,13 @@ to allow protection of + * VimColor code blocks so that code isn't accidentally interpreted as WikiText + * or escaped as HTML. + * + * -- jerith, 22 August 2005 + */ + /** * @file * Handle filtering of Wiki Text @@ -8,6 +15,8 @@ define('WIKI_FILTER_HTML_ENABLE', 1); define('WIKI_FILTER_HTML_DISABLE', 2); +define('WIKI_FILTER_VIMCOLOR_ENABLE', 1); +define('WIKI_FILTER_VIMCOLOR_DISABLE', 2); /** * Implementation of hook_help(). @@ -69,6 +78,8 @@ */ function _wiki_filter_settings($format) { $group = form_radios(t('Support Escaped HTML'), "wiki_filter_html", variable_get("wiki_filter_html", WIKI_FILTER_HTML_DISABLE), array(WIKI_FILTER_HTML_ENABLE => t('Enable HTML'), WIKI_FILTER_HTML_DISABLE => t('Disable HTML')), t('Whether to allow |>-escaped HTML. If set to "enable", then any HTML goes on each line after the |> escape marker. If set to "disable", then any HTML tags will be shown as is, unless the HTML Filter has been separately enabled. It is recommended that this be disabled. Turn on the HTML Filter to support HTML, but make sure the HTML filter applies after the WikiText filter.')); + //$output .= form_group(t('WikiText filter'), $group); + $group .= form_radios(t('Support VimColor filter'), "wiki_filter_vimcolor", variable_get("wiki_filter_vimcolor", WIKI_FILTER_VIMCOLOR_DISABLE), array(WIKI_FILTER_VIMCOLOR_ENABLE => t('Enable VimColor'), WIKI_FILTER_VIMCOLOR_DISABLE => t('Disable VimColor')), t('Whether to allow escaping of VimColor code blocks. If set to "enable", then code blocks escaped by the VimColor filter will be left as-is. Turn on the VimColor filter to syntax-highlight code, but make sure the it applies after the WikiText filter. This option should be left disabled unless VimColor is enabled.')); $output .= form_group(t('WikiText filter'), $group); return $output; @@ -357,6 +368,7 @@ function _wiki_filter($text) { $html = ''; $isprotect = FALSE; // whether we're within a {{{ }}} protection block + $iscode = FALSE; // whether we're within a VimColor protection block $istable = FALSE; // whether we're currently in a table // process text line by line @@ -371,6 +383,40 @@ $tmpline = $lines[$index]; + // fully protect everthing within a VimColor block. + // multi line case: + if (variable_get("wiki_filter_vimcolor", WIKI_FILTER_VIMCOLOR_DISABLE) == WIKI_FILTER_VIMCOLOR_ENABLE) { + if (preg_match('/^\xFEcode_start:[a-z]*\xFF(.*)/', $tmpline, $matches) && !preg_match('/\xFE\/code_end\xFF/', $tmpline, $matches)) { + $iscode = TRUE; + $html .= _wiki_set_output_mode("", WIKI_ZERO_LEVEL, 0)."\n"; + $html .= $tmpline."\n"; + continue; + } + elseif ($iscode) { + if (preg_match('/^(\xFE\/code_end\xFF)/', $tmpline, $matches)) { + $iscode = FALSE; + $html .= $matches[1]."\n"; + $html .= _wiki_set_output_mode("", WIKI_ZERO_LEVEL, 0); + } + else { + $html .= $tmpline. "\n"; + } + continue; + } + + // single line case: + $oldn = $ntokens; + $tmpline = _wiki_tokenize($tmpline, '\xFEcode_start:[a-z]*\xFF.+\xFE\/code_end\xFF', $replacements, $ntokens); + while ($oldn < $ntokens) { + if (preg_match('/\xFEcode_start:([a-z]*)\xFF(.+)\xFE\/code_end\xFF/', $replacements[$oldn], $matches)) { + // this, of course, goes through, but we want the matched piece + $matches[2] = str_replace('\\\\', '
', $matches[2]); + $replacements[$oldn] = preg_replace('/\xFEcode_start:[a-z]*\xFF.+\xFE\/code_end\xFF/', "\xFEcode_start:".$matches[1]."\xFF".$matches[2]."\xFE/code_end\xFF", $replacements[$oldn]); + } + $oldn++; + } + } + // protect everthing within "{{{" and "}}}" as is // multi line case: if (preg_match("/^{{{(.*)/", $tmpline, $matches) && !preg_match("/}}}/", $tmpline, $matches)) {