1<?php
2/**
3 * Plugin No Abstract: Exclude certain parts of a page from the abstract in metadata.
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Jumptohistory <jumptohistory@gmail.com>
7 */
8
9if(!defined('DOKU_INC')) die();
10
11class syntax_plugin_noabstract extends DokuWiki_Syntax_Plugin {
12    public function getType() { return 'container'; }
13    public function getSort() { return 32; }
14    public function getAllowedTypes() { return array('formatting', 'substition', 'disabled', 'protected', 'container', 'baseonly'); }
15    public function connectTo($mode) {
16        $this->Lexer->addEntryPattern('<noabstract>(?=.*?</noabstract>)',$mode,'plugin_noabstract');
17        $this->Lexer->addSpecialPattern('~~NOABSTRACT~~', $mode, 'plugin_noabstract');
18    }
19    public function postConnect() { $this->Lexer->addExitPattern('</noabstract>','plugin_noabstract'); }
20
21    public function handle($match, $state, $pos, Doku_Handler $handler) {
22        return array($state, $match);
23    }
24
25    protected $captureDefault;
26
27    public function render($mode, Doku_Renderer $renderer, $data) {
28        list($state,$match) = $data;
29        if($mode == 'xhtml'){
30            switch ($state) {
31            case DOKU_LEXER_UNMATCHED:
32                $renderer->doc .= $renderer->_xmlEntities($match);
33                break;
34            }
35            return true;
36        } else if($mode == 'metadata'){
37            switch ($state) {
38            case DOKU_LEXER_ENTER:
39                $this->captureDefault = $renderer->capture;
40                $renderer->capture = false;
41                break;
42            case DOKU_LEXER_SPECIAL:
43               $renderer->capture = false;
44               break;
45            case DOKU_LEXER_EXIT:
46                $renderer->capture = $this->captureDefault;
47                break;
48            }
49            return true;
50        }
51        return false;
52    }
53}
54