".Keep($text).""; $text = preg_replace("/\n[^\\S\n]+$/", "\n", $text); if ($lead == "" || $lead == "\n") return "$lead
".Keep($text)."
"; return "$lead<:pre,1>".Keep($text); } Markup('[=','_begin',"/(\n[^\\S\n]*)?\\[([=@])(.*?)\\2\\]/se", "PreserveText('$2', PSS('$3'), '$1')"); Markup('restore','<_end',"/$KeepToken(\\d.*?)$KeepToken/e", '$GLOBALS[\'KPV\'][\'$1\']'); Markup('<:', '>restore', '/<:[^>]*>/', ''); Markup('', '/', "
"); Markup('

', '<', "/]*)(\\s)class=(['\"])([^>]*?)\\4)?/", "[=', '/\\$\\[(?>([^\\]]+))\\]/e', "NoCache(XL(PSS('$1')))"); # {$var} substitutions Markup('{$var}', '>$[phrase]', '/\\{(\\*|!?[-\\w.\\/\\x80-\\xff]*)(\\$:?\\w+)\\}/e', "PRR(PVSE(PageVar(\$pagename, '$2', '$1')))"); # invisible (:textvar:...:) definition Markup('textvar:', '([A-Za-z0-9]+|#\\d+|#[xX][A-Fa-f0-9]+));/', '&$1;'); Markup('&amp;', '<&', '/&amp;/', Keep('&')); ## (:if:)/(:elseif:)/(:else:) Markup('if', 'fulltext', "/ \\(:if (?:end)? \\b[^\n]*?:\\) .*? (?: \\(: (?:if|ifend) \\s* :\\) | (?=\\(:(?:if|ifend)\\b[^\n]*?:\\) | $) ) /seix", "CondText2(\$pagename, PSS('$0'))"); function CondText2($pagename, $text) { global $Conditions; $parts = preg_split('/\\(:(?:ifend|if|else *if|else)\\b\\s*(.*?)\\s*:\\)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE); $x = array_shift($parts); while ($parts) { list($condspec, $condtext) = array_splice($parts, 0, 2); if (!preg_match("/^\\s*(!?)\\s*(\\S*)\\s*(.*?)\\s*$/", $condspec, $match)) continue; list($x, $not, $condname, $condparm) = $match; if (!isset($Conditions[$condname])) return $condtext; $tf = @eval("return ({$Conditions[$condname]});"); if ($tf xor $not) return $condtext; } return ''; } ## (:include:) Markup('include', '>if', '/\\(:include\\s+(\\S.*?):\\)/ei', "PRR(IncludeText(\$pagename, PSS('$1')))"); ## (:redirect:) Markup('redirect', 'include', '/\\(:nogroupheader:\\)/ei', "PZZ(\$GLOBALS['GroupHeaderFmt']='')"); Markup('nogroupfooter', '>include', '/\\(:nogroupfooter:\\)/ei', "PZZ(\$GLOBALS['GroupFooterFmt']='')"); Markup('groupheader', '>nogroupheader', '/\\(:groupheader:\\)/ei', "PRR(FmtPageName(\$GLOBALS['GroupHeaderFmt'],\$pagename))"); Markup('groupfooter','>nogroupfooter', '/\\(:groupfooter:\\)/ei', "PRR(FmtPageName(\$GLOBALS['GroupFooterFmt'],\$pagename))"); ## (:nl:) Markup('nl0','(?:\\(:nl:\\))+)([^\n])/i","$1\n$2"); Markup('nl1','>nl0',"/\\(:nl:\\)/i",''); ## \\$ (end of line joins) Markup('\\$','>nl1',"/\\\\(?>(\\\\*))\n/e", "str_repeat('
',strlen('$1'))"); ## Remove one <:vspace> after !headings Markup('!vspace', '>\\$', "/^(!(?>[^\n]+)\n)<:vspace>/m", '$1'); ## (:noheader:),(:nofooter:),(:notitle:)... Markup('noheader', 'directives', '/\\(:noheader:\\)/ei', "SetTmplDisplay('PageHeaderFmt',0)"); Markup('nofooter', 'directives', '/\\(:nofooter:\\)/ei', "SetTmplDisplay('PageFooterFmt',0)"); Markup('notitle', 'directives', '/\\(:notitle:\\)/ei', "SetTmplDisplay('PageTitleFmt',0)"); Markup('noleft', 'directives', '/\\(:noleft:\\)/ei', "SetTmplDisplay('PageLeftFmt',0)"); Markup('noright', 'directives', '/\\(:noright:\\)/ei', "SetTmplDisplay('PageRightFmt',0)"); Markup('noaction', 'directives', '/\\(:noaction:\\)/ei', "SetTmplDisplay('PageActionFmt',0)"); ## (:spacewikiwords:) Markup('spacewikiwords', 'directives', '/\\(:(no)?spacewikiwords:\\)/ei', "PZZ(\$GLOBALS['SpaceWikiWords']=('$1'!='no'))"); ## (:linkwikiwords:) Markup('linkwikiwords', 'directives', '/\\(:(no)?linkwikiwords:\\)/ei', "PZZ(\$GLOBALS['LinkWikiWords']=('$1'!='no'))"); ## (:linebreaks:) Markup('linebreaks', 'directives', '/\\(:(no)?linebreaks:\\)/ei', "PZZ(\$GLOBALS['HTMLPNewline'] = ('$1'!='no') ? '
' : '')"); ## (:messages:) Markup('messages', 'directives', '/^\\(:messages:\\)/ei', "'<:block>'.Keep( FmtPageName(implode('',(array)\$GLOBALS['MessagesFmt']), \$pagename))"); ## (:comment:) Markup('comment', 'directives', '/\\(:comment .*?:\\)/i', ''); ## (:title:) Markup('title','directives', '/\\(:title\\s(.*?):\\)/ei', "PZZ(PCache(\$pagename, \$zz=array('title' => SetProperty(\$pagename, 'title', PSS('$1')))))"); ## (:keywords:), (:description:) Markup('keywords', 'directives', "/\\(:keywords?\\s+(.+?):\\)/ei", "PZZ(SetProperty(\$pagename, 'keywords', PSS('$1'), ', '))"); Markup('description', 'directives', "/\\(:description\\s+(.+?):\\)/ei", "PZZ(SetProperty(\$pagename, 'description', PSS('$1'), '\n'))"); $HTMLHeaderFmt['meta'] = 'function:PrintMetaTags'; function PrintMetaTags($pagename, $args) { global $PCache; foreach(array('keywords', 'description') as $n) { foreach((array)@$PCache[$pagename]["=p_$n"] as $v) { $v = str_replace("'", ''', $v); print "\n"; } } } #### inline markups #### ## ''emphasis'' Markup("''",'inline',"/''(.*?)''/",'$1'); ## '''strong''' Markup("'''","<''","/'''(.*?)'''/",'$1'); ## '''''strong emphasis''''' Markup("'''''","<'''","/'''''(.*?)'''''/",'$1'); ## @@code@@ Markup('@@','inline','/@@(.*?)@@/','$1'); ## '+big+', '-small-' Markup("'+","<'''''","/'\\+(.*?)\\+'/",'$1'); Markup("'-","<'''''","/'\\-(.*?)\\-'/",'$1'); ## '^superscript^', '_subscript_' Markup("'^","<'''''","/'\\^(.*?)\\^'/",'$1'); Markup("'_","<'''''","/'_(.*?)_'/",'$1'); ## [+big+], [-small-] Markup('[+','inline','/\\[(([-+])+)(.*?)\\1\\]/e', "''. PSS('$3')"); ## {+ins+}, {-del-} Markup('{+','inline','/\\{\\+(.*?)\\+\\}/','$1'); Markup('{-','inline','/\\{-(.*?)-\\}/','$1'); ## [[<<]] (break) Markup('[[<<]]','inline','/\\[\\[<<\\]\\]/',"
"); ###### Links ###### ## [[free links]] Markup('[[','links',"/(?>\\[\\[\\s*(.*?)\\]\\])($SuffixPattern)/e", "Keep(MakeLink(\$pagename,PSS('$1'),NULL,'$2'),'L')"); ## [[!Category]] SDV($CategoryGroup,'Category'); SDV($LinkCategoryFmt,"\$LinkText"); Markup('[[!','<[[','/\\[\\[!(.*?)\\]\\]/e', "Keep(MakeLink(\$pagename,PSS('$CategoryGroup/$1'),NULL,'',\$GLOBALS['LinkCategoryFmt']),'L')"); # This is a temporary workaround for blank category pages. # It may be removed in a future release (Pm, 2006-01-24) if (preg_match("/^$CategoryGroup\\./", $pagename)) { SDV($DefaultPageTextFmt, ''); SDV($PageNotFoundHeaderFmt, 'HTTP/1.1 200 Ok'); } ## [[target | text]] Markup('[[|','<[[', "/(?>\\[\\[([^|\\]]*)\\|\\s*)(.*?)\\s*\\]\\]($SuffixPattern)/e", "Keep(MakeLink(\$pagename,PSS('$1'),PSS('$2'),'$3'),'L')"); ## [[text -> target ]] Markup('[[->','>[[|', "/(?>\\[\\[([^\\]]+?)\\s*-+>\\s*)(.*?)\\]\\]($SuffixPattern)/e", "Keep(MakeLink(\$pagename,PSS('$2'),PSS('$1'),'$3'),'L')"); if (IsEnabled($EnableRelativePageLinks, 1)) SDV($QualifyPatterns['/(\\[\\[(?>[^\\]]+?->)?\\s*)([-\\w\\s\'()]+([|#?].*?)?\\]\\])/e'], "PSS('$1').\$group.PSS('/$2')"); ## [[#anchor]] Markup('[[#','<[[','/(?>\\[\\[#([A-Za-z][-.:\\w]*))\\]\\]/e', "Keep(TrackAnchors('$1') ? '' : \"\", 'L')"); function TrackAnchors($x) { global $SeenAnchor; return @$SeenAnchor[$x]++; } ## [[target |#]] reference links Markup('[[|#', '<[[|', "/(?>\\[\\[([^|\\]]+))\\|\\s*#\\s*\\]\\]/e", "Keep(MakeLink(\$pagename,PSS('$1'),'['.++\$MarkupFrame[0]['ref'].']'),'L')"); ## [[target |+]] title links Markup('[[|+', '<[[|', "/(?>\\[\\[([^|\\]]+))\\|\\s*\\+\\s*]]/e", "Keep(MakeLink(\$pagename, PSS('$1'), PageVar(MakePageName(\$pagename,PSS('$1')), '\$Title') ),'L')"); ## bare urllinks Markup('urllink','>[[', "/\\b(?>(\\L))[^\\s$UrlExcludeChars]*[^\\s.,?!$UrlExcludeChars]/e", "Keep(MakeLink(\$pagename,'$0','$0'),'L')"); ## mailto: links Markup('mailto','(\\L))([^\\s$UrlExcludeChars]+$ImgExtPattern)(\"([^\"]*)\")?/e", "Keep(\$GLOBALS['LinkFunctions']['$1'](\$pagename,'$1','$2','$4','$1$2', \$GLOBALS['ImgTagFmt']),'L')"); ## bare wikilinks ## v2.2: markup rule moved to scripts/wikiwords.php) Markup('wikilink', '>urllink'); ## escaped `WikiWords ## v2.2: rule kept here for markup compatibility with 2.1 and earlier Markup('`wikiword', ' markup (after all other block markups) Markup('^<:','>block','/^(?=\\s*\\S)(<:([^>]+)>)?/e',"Block('$2')"); ## unblocked lines w/block markup become anonymous <:block> Markup('^!<:', '<^<:', "/^(?!<:)(?=.*(<\\/?($BlockPattern)\\b)|$KeepToken\\d+B$KeepToken)/", '<:block>'); ## Lines that begin with displayed images receive their own block. A ## pipe following the image indicates a "caption" (generates a linebreak). Markup('^img', 'block', "/^((?>(\\s+|%%|%[A-Za-z][-,=:#\\w\\s'\".]*%)*)$KeepToken(\\d+L)$KeepToken)(\\s*\\|\\s?)?(.*)$/e", "PSS((strpos(\$GLOBALS['KPV']['$3'],'

$1' . ('$4' ? '
' : '') .'$5
')"); ## Whitespace at the beginning of lines can be used to maintain the ## indent level of a previous list item, or a preformatted text block. Markup('^ws', '<^img', '/^\\s+ #1/ex', "WSIndent('$0')"); function WSIndent($i) { global $MarkupFrame; $icol = strlen($i); for($depth = count(@$MarkupFrame[0]['cs']); $depth > 0; $depth--) if (@$MarkupFrame[0]['is'][$depth] == $icol) { $MarkupFrame[0]['idep'] = $depth; $MarkupFrame[0]['icol'] = $icol; return ''; } return $i; } ## The $EnableWSPre setting uses leading spaces on markup lines to indicate ## blocks of preformatted text. SDV($EnableWSPre, 1); Markup('^ ', 'block', '/^\\s+ #2/ex', "(\$GLOBALS['EnableWSPre'] > 0 && strlen('$0') >= \$GLOBALS['EnableWSPre']) ? '<:pre,1>$0' : '$0'"); ## bullet lists Markup('^*','block','/^(\\*+)\\s?(\\s*)/','<:ul,$1,$0>$2'); ## numbered lists Markup('^#','block','/^(#+)\\s?(\\s*)/','<:ol,$1,$0>$2'); ## indented (->) /hanging indent (-<) text Markup('^->','block','/^(?>(-+))>\\s?(\\s*)/','<:indent,$1,$1 $2>$2'); Markup('^-<','block','/^(?>(-+))<\\s?(\\s*)/','<:outdent,$1,$1 $2>$2'); ## definition lists Markup('^::','block','/^(:+)(\s*)([^:]+):/','<:dl,$1,$1$2>
$2$3
'); ## Q: and A: Markup('^Q:', 'block', '/^Q:(.*)$/', "<:block,1>

$1

"); Markup('^A:', 'block', '/^A:/', Keep('')); ## tables ## ||cell||, ||!header cell||, ||!caption!|| Markup('^||||', 'block', '/^\\|\\|.*\\|\\|.*$/e', "FormatTableRow(PSS('$0'))"); ## ||table attributes Markup('^||','>^||||','/^\\|\\|(.*)$/e', "PZZ(\$GLOBALS['BlockMarkups']['table'][0] = '') .'<:block,1>'"); ## headings Markup('^!', 'block', '/^(!{1,6})\\s?(.*)$/e', "'<:block,1>$2'"); ## horiz rule Markup('^----','>^->','/^----+/','<:block,1>
'); #### (:table:) markup (AdvancedTables) function Cells($name,$attr) { global $MarkupFrame; $attr = PQA($attr); $tattr = @$MarkupFrame[0]['tattr']; $name = strtolower($name); $key = preg_replace('/end$/', '', $name); if (strncmp($key, 'cell', 4) == 0) $key = 'cell'; $out = '<:block>'.MarkupClose($key); if (substr($name, -3) == 'end') return $out; $cf = & $MarkupFrame[0]['closeall']; if ($name == 'table') $MarkupFrame[0]['tattr'] = $attr; else if (strncmp($name, 'cell', 4) == 0) { if (strpos($attr, "valign=")===false) $attr .= " valign='top'"; if (!@$cf['table']) { $tattr = @$MarkupFrame[0]['tattr']; $out .= "
"; $cf['table'] = '
'; } else if ($name == 'cellnr') $out .= ""; else $out .= ""; $cf['cell'] = ''; } else { $out .= "
"; $cf[$key] = '
'; } return $out; } Markup('table', '>', '><<', '<^>>', '/^>><</', '(:divend:)'); #### special stuff #### ## (:markup:) for displaying markup examples function MarkupMarkup($pagename, $text, $opt = '') { $MarkupMarkupOpt = array('class' => 'vert'); $opt = array_merge($MarkupMarkupOpt, ParseArgs($opt)); $html = MarkupToHTML($pagename, $text, array('escape' => 0)); if (@$opt['caption']) $caption = str_replace("'", ''', "{$opt['caption']}"); $class = preg_replace('/[^-\\s\\w]+/', ' ', @$opt['class']); if (strpos($class, 'horiz') !== false) { $sep = ''; $pretext = wordwrap($text, 40); } else { $sep = ''; $pretext = wordwrap($text, 75); } return Keep(@"$caption $sep
$pretext
$html
"); } Markup('markup', '<[=', "/\\(:markup(\\s+([^\n]*?))?:\\)[^\\S\n]*\\[([=@])(.*?)\\3\\]/sei", "MarkupMarkup(\$pagename, PSS('$4'), PSS('$2'))"); Markup('markupend', '>markup', "/\\(:markup(\\s+([^\n]*?))?:\\)[^\\S\n]*\n(.*?)\\(:markupend:\\)/sei", "MarkupMarkup(\$pagename, PSS('$3'), PSS('$1'))"); SDV($HTMLStylesFmt['markup'], " table.markup { border:2px dotted #ccf; width:90%; } td.markup1, td.markup2 { padding-left:10px; padding-right:10px; } table.vert td.markup1 { border-bottom:1px solid #ccf; } table.horiz td.markup1 { width:23em; border-right:1px solid #ccf; } table.markup caption { text-align:left; } div.faq p, div.faq pre { margin-left:2em; } div.faq p.question { margin:1em 0 0.75em 0; font-weight:bold; } div.faqtoc div.faq * { display:none; } div.faqtoc div.faq p.question { display:block; font-weight:normal; margin:0.5em 0 0.5em 20px; line-height:normal; } div.faqtoc div.faq p.question * { display:inline; } "); #### Special conditions #### ## The code below adds (:if date:) conditions to the markup. $Conditions['date'] = "CondDate(\$condparm)"; function CondDate($condparm) { global $Now; if (!preg_match('/^(\\S*?)(\\.\\.(\\S*))?(\\s+\\S.*)?$/', trim($condparm), $match)) return false; if ($match[4] == '') { $x0 = $Now; NoCache(); } else { list($x0, $x1) = DRange($match[4]); } if ($match[1] > '') { list($t0, $t1) = DRange($match[1]); if ($x0 < $t0) return false; if ($match[2] == '' && $x0 >= $t1) return false; } if ($match[3] > '') { list($t0, $t1) = DRange($match[3]); if ($x0 >= $t1) return false; } return true; } # This pattern enables the (:encrypt :) markup/replace-on-save # pattern. SDV($ROSPatterns['/\\(:encrypt\\s+([^\\s:=]+).*?:\\)/e'], "crypt(PSS('$1'))");