예제 #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 testGetMenuTraversesLevelsCorrectly()
 {
     $obj = new TocGenerator();
     $html = "\n            <h1 id='a'>A-Header</h1><p>Foobar</p>\n            <h2 id='b'>B-Header</h2>\n            <h2 id='c'>C-Header</h2>\n            <h3 id='d'>D-Header</h3>\n            <h4 id='e'>E-Header</h4>\n            <h2 id='f'>F-Header</h2>\n            <h5 id='g'>G-Header</h5>\n            <h1 id='h'>H-Header</h1><div>Hi</div>\n        ";
     $fixture = array_filter(array_map('trim', file(__DIR__ . '/fixtures/testHtmlList.html')));
     $actual = array_filter(array_map('trim', explode(PHP_EOL, $obj->getHtmlMenu($html, 1, 6))));
     $this->assertEquals($fixture, $actual);
 }