当前位置: 首页>>代码示例>>PHP>>正文


PHP ParserOutput::setTOCHTML方法代码示例

本文整理汇总了PHP中ParserOutput::setTOCHTML方法的典型用法代码示例。如果您正苦于以下问题:PHP ParserOutput::setTOCHTML方法的具体用法?PHP ParserOutput::setTOCHTML怎么用?PHP ParserOutput::setTOCHTML使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ParserOutput的用法示例。


在下文中一共展示了ParserOutput::setTOCHTML方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: formatHeadings


//.........这里部分代码省略.........
         if ($enoughToc && (!isset($wgMaxTocLevel) || $toclevel < $wgMaxTocLevel)) {
             $toc .= Linker::tocLine($anchor, $tocline, $numbering, $toclevel, $isTemplate ? false : $sectionIndex);
         }
         # Add the section to the section tree
         # Find the DOM node for this header
         $noOffset = $isTemplate || $sectionIndex === false;
         while ($node && !$noOffset) {
             if ($node->getName() === 'h') {
                 $bits = $node->splitHeading();
                 if ($bits['i'] == $sectionIndex) {
                     break;
                 }
             }
             $byteOffset += mb_strlen($this->mStripState->unstripBoth($frame->expand($node, PPFrame::RECOVER_ORIG)));
             $node = $node->getNextSibling();
         }
         $tocraw[] = array('toclevel' => $toclevel, 'level' => $level, 'line' => $tocline, 'number' => $numbering, 'index' => ($isTemplate ? 'T-' : '') . $sectionIndex, 'fromtitle' => $titleText, 'byteoffset' => $noOffset ? null : $byteOffset, 'anchor' => $anchor);
         # give headline the correct <h#> tag
         if ($maybeShowEditLink && $sectionIndex !== false) {
             // Output edit section links as markers with styles that can be customized by skins
             if ($isTemplate) {
                 # Put a T flag in the section identifier, to indicate to extractSections()
                 # that sections inside <includeonly> should be counted.
                 $editlinkArgs = array($titleText, "T-{$sectionIndex}");
             } else {
                 $editlinkArgs = array($this->mTitle->getPrefixedText(), $sectionIndex, $headlineHint);
             }
             // We use a bit of pesudo-xml for editsection markers. The language converter is run later on
             // Using a UNIQ style marker leads to the converter screwing up the tokens when it converts stuff
             // And trying to insert strip tags fails too. At this point all real inputted tags have already been escaped
             // so we don't have to worry about a user trying to input one of these markers directly.
             // We use a page and section attribute to stop the language converter from converting these important bits
             // of data, but put the headline hint inside a content block because the language converter is supposed to
             // be able to convert that piece of data.
             $editlink = '<mw:editsection page="' . htmlspecialchars($editlinkArgs[0]);
             $editlink .= '" section="' . htmlspecialchars($editlinkArgs[1]) . '"';
             if (isset($editlinkArgs[2])) {
                 $editlink .= '>' . $editlinkArgs[2] . '</mw:editsection>';
             } else {
                 $editlink .= '/>';
             }
         } else {
             $editlink = '';
         }
         $head[$headlineCount] = Linker::makeHeadline($level, $matches['attrib'][$headlineCount], $anchor, $headline, $editlink, $legacyAnchor);
         $headlineCount++;
     }
     $this->setOutputType($oldType);
     # Never ever show TOC if no headers
     if ($numVisible < 1) {
         $enoughToc = false;
     }
     if ($enoughToc) {
         if ($prevtoclevel > 0 && $prevtoclevel < $wgMaxTocLevel) {
             $toc .= Linker::tocUnindent($prevtoclevel - 1);
         }
         $toc = Linker::tocList($toc, $this->mOptions->getUserLangObj());
         $this->mOutput->setTOCHTML($toc);
         $toc = self::TOC_START . $toc . self::TOC_END;
     }
     if ($isMain) {
         $this->mOutput->setSections($tocraw);
     }
     # split up and insert constructed headlines
     $blocks = preg_split('/<H[1-6].*?' . '>[\\s\\S]*?<\\/H[1-6]>/i', $text);
     $i = 0;
     // build an array of document sections
     $sections = array();
     foreach ($blocks as $block) {
         // $head is zero-based, sections aren't.
         if (empty($head[$i - 1])) {
             $sections[$i] = $block;
         } else {
             $sections[$i] = $head[$i - 1] . $block;
         }
         /**
          * Send a hook, one per section.
          * The idea here is to be able to make section-level DIVs, but to do so in a
          * lower-impact, more correct way than r50769
          *
          * $this : caller
          * $section : the section number
          * &$sectionContent : ref to the content of the section
          * $showEditLinks : boolean describing whether this section has an edit link
          */
         wfRunHooks('ParserSectionCreate', array($this, $i, &$sections[$i], $showEditLink));
         $i++;
     }
     if ($enoughToc && $isMain && !$this->mForceTocPosition) {
         // append the TOC at the beginning
         // Top anchor now in skin
         $sections[0] = $sections[0] . $toc . "\n";
     }
     $full .= join('', $sections);
     if ($this->mForceTocPosition) {
         return str_replace('<!--MWTOC-->', $toc, $full);
     } else {
         return $full;
     }
 }
开发者ID:Tarendai,项目名称:spring-website,代码行数:101,代码来源:Parser.php


注:本文中的ParserOutput::setTOCHTML方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。