function toctoggle(obj, hide, show) { var elstyle = document.getElementById(obj).style; var text = document.getElementById(obj + \"tog\"); if(!hide) { var hide = \"{$ToggleText[0]}\"; } if(!show) { var show = \"{$ToggleText[1]}\"; } if (elstyle.display == 'none') { elstyle.display = 'block'; text.innerHTML = hide; } else { elstyle.display = 'none'; text.innerHTML = show; } } "; ## section cross-references Markup('secref','>nl1','/(`)?(Sec|SEC)\\(([A-Za-z][-.:\w]*)\\)/', function ($m) use (&$pagename) { return CrossReferenceList($pagename,$m[1],$m[2],$m[3]); }); function CrossReferenceList($pagename,$prefix,$ref,$anchor) { global $ReferenceList, $format; $txt = PageCrossReference($pagename,$anchor); if ($format=='pdf') { $anch = "$pagename.$anchor"; $ReferenceList[$anch] = $txt; return "$prefix$ref( $anch )"; } return "[[#$anchor | $txt]]"; } ## in-page cross-references Markup('[[#|#','>nl1','/\[\[#([A-Za-z][-.:\w]*)\s*\|\s+#\]\]/', function ($m) use (&$pagename) { return '[[#'.$m[1].' | '.PageCrossReference($pagename,$m[1]).']]'; }); Markup('[[#|*','<[[|','/\[\[#([A-Za-z][-.:\w]*)\s*\|\s*\*\]\]/', '[[#$1 | $1]]'); Markup('[[#|+','<[[|','/\[\[#([A-Za-z][-.:\w]*)\s*\|\s*\+\]\]/', '[[#$1 | Back to $1]]'); Markup("[^#",'<[[#|#','/\[\^#([A-Za-z][-.:\w]*)\^\]/', function ($m) use (&$pagename) { return PageCrossReference($pagename,$m[1],false); }); # if markup.php is not loaded, we need a link cleaner SDV($LinkCleanerEnabled, false); if (!$LinkCleanerEnabled) { function isClosure($r) { return (is_object($r) && ($r instanceof Closure)); } function cleanLinkText($pagename, $text) { global $LinkCleaner; foreach ($LinkCleaner as $p => $r) { $text = isClosure($r) ? preg_replace_callback($p,$r,$text) : preg_replace($p,$r,$text); } return $text; } SDVA($LinkCleaner, array( '/`\..*?$/' => '...', "/\\{(\\$.*?)\\}/" => '$1', "/\\[\\[([^|\\]]+)\\|\\s*(.*?)\\]\\]($SuffixPattern)/" => function ($m) use (&$pagename) { return MakeLink($pagename,$m[1],$m[2],$m[3],'$LinkText'); }, "/\\[\\[([^\\]]+?)\\s*-+>\\s*(.*?)\\]\\]($SuffixPattern)/" => function ($m) use (&$pagename) { return MakeLink($pagename,$m[2],$m[1],$m[3],'$LinkText'); }, '/\\[\\[#([A-Za-z][-.:\\w]*)\\]\\]/' => "", "/\\[\\[(.*?)\\]\\]($SuffixPattern)/" => function ($m) use (&$pagename) { return MakeLink($pagename,$m[1],NULL,$m[2],'$LinkText'); }, '/[\\[\\{](.*?)\\|(.*?)[\\]\\}]/' => '$1', "/`(($GroupPattern([\\/.]))?($WikiWordPattern))/" => '$1', "/$GroupPattern\\/($WikiWordPattern)/" => '$1' )); } function CrossReference($pagename,$text,$anchor) { $r = Shortcut($text,$anchor); return trim(cleanLinkText($pagename,$r)); } function Shortcut($text,$anchor) { if (preg_match("/\\[\\[#+$anchor\\]\\]\\n?([^\n]+)/",$text,$match)) { return preg_replace("/^[#*!:]+\s*/","", preg_replace("/([^!]+)!.+/","$1",$match[1])); } else { return "$anchor not found"; } } ## inter-page cross-references Markup('[[?#|#','>nl1', "/\[\[((?:$GroupPattern)[.\/])?($NamePattern)#([A-Za-z][-.:\w]*)\s*\|\s+#\]\]/", function ($m) use (&$pagename) { return '[['.$m[1].$m[2].'#'.$m[3].' | '.PageCrossReference(MakePageName($pagename,$m[1].$m[2]),$m[3]).']]'; }); function PageCrossReference($page,$anchor,$clean=true) { global $PCache; if ($PCache[$page]['=preview']) $p['text'] = $PCache[$page]['=preview']; else $p = RetrieveAuthPage($page,'read',false,READPAGE_CURRENT); return $clean ? CrossReference($page,$p['text'],$anchor) : Shortcut($p['text'],$anchor); } ## [[##visibleanchor]] SDV($VisibleAnchor,'§'); SDV($VisibleAnchorLinks,false); SDV($DefaultTocAnchor,'toc'); $RefOrTitle = ($VisibleAnchorLinks) ? 'href' : 'title'; ## autonumber anchors Markup('^!#','" . Keep("
" .
      wordwrap($txta, 70) . "
") . "\n$txtb\n(:divend:)
\n"; } Markup('`markup','$TocTitle'); SDV($RemoteTocFmt, 'Contents of [[$Toc(#toc)]]'); } else { SDV($DefaultTocTitle,'On this page...'); SDV($TocHeaderFmt,'[[#toc]]$TocTitle'); SDV($RemoteTocFmt,'On page [[$Toc(#toc)]]...'); } SDV($NumberToc,true); SDV($L1TocChar, '.'); SDV($OmitQMarkup,false); SDV($ToggleMarkup, true); if ($action=="print" || $action=="publish") { Markup('[[##','<[[#','/\[\[##([A-Za-z][-.:\w]*)\]\]/','[[#$1]]'); if ($action=='publish') Markup('toc','>include', '/\(:([#\*])?toc(?:-(float|hide))?(?:\s+anchors=(v)isible)?(?:\s+(.*?))?:\)/', ''); Markup('tocback','directives','/\(:toc-back(?:\s+(.*?))?:\)/',''); Markup('toggle', 'directives', '/\\(:toggle(\*)?\s*(.*?):\\)/', ''); } else { Markup('[[##','<[[#','/\[\[##([A-Za-z][-.:\w]*)\]\]/', "anchorHelper"); if ($ToggleMarkup) { Markup('toggle', 'directives','/^(.*?)\\(:toggle(\*)?\s*(.*?):\\)/', "toggleHelper"); Markup('toghide', '>style', '/<(?:div|table|[oud]l)\s*[^>]*id=["\']([^"\']+)[^>]*>/', function ($m) { return FmtToggleHide($m[0], $m[1]); }); } } Markup('toc','>[[#|#', '/\(:([#\*])?toc(?:-(float|hide))?(?:\s+anchors=(v)isible)?(?:\s+(.*?))?(?:\s+(Q))?:\)(.*)$/s', function ($m) use (&$pagename) { return TableOfContents($pagename,$m[1],$m[2],$m[4],$m[5],$m[6]). TocEntryAnchors($m[3],$m[6]); }); SDV($TocBackFmt,'↑ Contents'); Markup('tocback','directives','/\(:toc-back(?:\s+(.*?))?:\)/',"TocLinkText"); Markup('tocpage','directives','/\(:toc-page\s+(.*?)(?:\s+self=([01]))?:\)/', function ($m) use (&$pagename) { return RemoteTableOfContents($pagename,$m[1],$m[2]); }); function anchorHelper($m) { global $RefOrTitle, $VisibleAnchor; return Keep("". "". "$VisibleAnchor", 'L'); } function toggleHelper($m) { return ($m[1] ? $m[1] : '<:block>'). '
'.Keep(FmtToggleLinks($m[2], $m[3])).'
'; } function FmtToggleLinks($hidden, $opts) { global $ToggleText, $ToggleHideID; $opt = ParseArgs($opts); $hide = $opt['hide'] ? $opt['hide'] : $ToggleText[0]; $show = $opt['show'] ? $opt['show'] : $ToggleText[1]; if ($opt['id']) $id = $opt['id']; else return "(:toggle$hidden $opts :)"; $txt = $hidden ? $show : $hide; if ($hidden) $ToggleHideID[] = $id; if ($opt['button']) { $tag = 'button'; $att = 'onclick'; } else { $tag = 'a'; $att = 'href'; } return "<$tag id='$id"."tog' $att=\"javascript:toctoggle('$id','$hide','$show');\">$txt"; } function FmtToggleHide($tag, $id) { global $ToggleHideID; foreach((array)$ToggleHideID as $i) if ($id==$i) if (preg_match('/\s+(style=["\'])[^"\']*(display:)?/', $tag, $m)) return $m[2] ? $tag : str_replace($m[1], $m[1].'display: none; ', $tag); else return str_replace('>', " style='display: none'>", $tag); return $tag; } function RemoteTableOfContents($pagename,$ref,$self=0) { global $TocHeaderFmt,$RemoteTocFmt; $oTocHeader = $TocHeaderFmt; $TocHeaderFmt = str_replace('$Toc',$ref,$RemoteTocFmt); $tocname = MakePageName($pagename,$ref); if ($tocname==$pagename && $self==0) return ''; $tocpage=RetrieveAuthPage($tocname,'read',false); $toctext=@$tocpage['text']; if (strpos($toctext, '(:nogroupheader:)')===false) $toctext = $GLOBALS['GroupHeaderFmt'].$toctext; if (preg_match('/\(:([#\*])?toc(?:-(float|hide))?(?:\s+anchors=(v)isible)?(?:\s+(.*?))?(?:\s+(Q))?:\)(.*)$/se',$toctext,$m)) $toc = str_replace('[[#',"[[$ref#", TableOfContents($tocname,$m[1],'page','',$m[5],PSS($m[6]))); $TocHeaderFmt = $oTocHeader; return $toc; } function TocLinkText($m) { global $TocBackFmt; $text = $m[1]; if ($text) $TocBackFmt = $text; return '[[#toc | '.$TocBackFmt.']]'; } function TocEntryAnchors($visible,$text) { global $IdPattern; return preg_replace_callback( "/\n(!+|Q:)\s*((\[\[#+$IdPattern\]\])|##?)?/", function ($m) use ($visible) { return "\n".$m[1].InsertAnchor($visible,$m[1],$m[2]); }, $text); } function InsertAnchor($visible,$h,$mark) { global $OmitQMarkup, $NumberToc, $L1TocChar; static $l1,$l2,$toc1,$toc2; if ($h=='Q:' && $OmitQMarkup) return $mark; if ($mark=='') $visibility = ($visible=='') ? '#' : '##'; else $visibility = $mark; if ($h=='Q:') return $visibility; $r = ''; $len = strlen($h); if ($l1==0) { $l1 = $len; } else if ($len!=$l1 && $l2==0) { $l2 = $len; } # if ($l1==$len || $l2==$len) $r = $visibility; if ($l1==$len) { $toc1++; $toc2 = 0; $r = $visibility; if ($NumberToc) $r .= "$toc1$L1TocChar  "; } elseif ($l2==$len) { $toc2++; $r = $visibility; if ($NumberToc) $r .= "$toc1.$toc2  "; } return $r; } function TableOfContents($pagename,$number,$float,$title,$includeq,$text) { global $DefaultTocTitle,$TocHeaderFmt,$IdPattern,$NumberToc,$OmitQMarkup, $format,$L1TocChar,$DefaultTocAnchor,$TocFloat,$HTMLHeaderFmt, $ToggleText; if ($includeq) $OmitQMarkup = (!$OmitQMarkup); if ($float=='float') $TocFloat = (!$TocFloat); $l1 = 0; $l2 = 0; $l3 = 0; $q = 0; $prelen = 1; $counter = 0; $r = ''; $toc1 = 0; $spacer = '  '; if (!$title) $title = $DefaultTocTitle; $toc = str_replace('$TocTitle',$title,$TocHeaderFmt); if ($number=='*') $NumberToc = false; elseif ($number=='#') $NumberToc = true; $closel = 0; if ($format=='pdf') { $l = 'tbook:item'; $s = ($NumberToc) ? 'tbook:enumerate' : 'tbook:itemize'; $sc = $s; $toc = "$toc". "<$sc><$l>\$List"; $flag = '!'; } elseif ($float=='hide') { return ''; } else { $tocid = ($float=='page') ? 'ptocid' : 'tocid'; // remote toc? $toggle = " ({$ToggleText[0]})"; $l = 'li'; $s = ($NumberToc) ? 'ol' : 'ul'; $sc = "$s class='toc'"; $f = ($TocFloat) ? 'float' : ''; $toc = "

$toc$toggle

" . "<$sc id='$tocid'><$l>\$List
"; $flag = ''; } preg_match_all("/\n(!+|Q?:)\s*(\[\[#+$IdPattern\]\]|#*)([^\n]*)/",$text, $match); for ($i=0;$i