コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function getFunctions()
 {
     $functions = parent::getFunctions();
     // ~~~
     $functions[] = new \Twig_SimpleFunction('toc', function ($markup, $top = 1, $depth = 6) {
         return $this->generator->getHtmlMenu($markup, $top, $depth);
     }, ['is_safe' => ['html']]);
     // ~~~
     $functions[] = new \Twig_SimpleFunction('toc_items', function ($markup, $top = 1, $depth = 6) {
         return $this->generator->getMenu($markup, $top, $depth);
     });
     $functions[] = new \Twig_SimpleFunction('add_anchors', function ($markup, $top = 1, $depth = 6) {
         return $this->fixer->fix($markup, $top, $depth);
     }, ['is_safe' => ['html']]);
     return $functions;
 }
コード例 #2
0
 public function testGetMenuReturnsAnEmptyArrayWhenNoContentOrMatches()
 {
     $obj = new TocGenerator();
     $this->assertEquals(0, count($obj->getMenu("<h1>Boo</h1><h2>Bar</h2>")));
     $this->assertEquals(0, count($obj->getMenu("")));
 }