1<?php
2/**
3 * Mediasyntax Plugin, listblock component: Mediawiki style ordered and unordered lists
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Esther Brunner <wikidesign@gmail.com>
7 */
8class syntax_plugin_mediasyntax_listblock extends DokuWiki_Syntax_Plugin
9{
10
11  function getType() { return 'container'; }
12  function getPType() { return 'block'; }
13  function getSort() { return 50; }
14
15  function getAllowedTypes()
16  {
17    return array('formatting', 'substition', 'disabled', 'protected');
18  }
19
20  function connectTo($mode)
21  {
22    // a list block starts with a new line starting with one or more * or # signs
23    $this->Lexer->addEntryPattern(
24      '^[ \t]*[\#\*]+ *',
25      $mode,
26      'plugin_mediasyntax_listblock'
27    );
28    // a list block continues as long as the following lines start with one or more * or # signs
29    $this->Lexer->addPattern(
30      '\n[ \t]*[\#\*\-]+ *',
31      'plugin_mediasyntax_listblock'
32    );
33  }
34
35  function postConnect()
36  {
37    $this->Lexer->addExitPattern(
38      '\n',
39      'plugin_mediasyntax_listblock'
40    );
41  }
42
43  function handle($match, $state, $pos, Doku_Handler $handler)
44  {
45    switch ($state)
46    {
47      case DOKU_LEXER_ENTER:
48        $ReWriter = new Doku_Handler_Mediasyntax_List($handler->getCallWriter());
49        $handler->setCallWriter($ReWriter);
50        $handler->addCall('list_open', array($match), $pos);
51        break;
52      case DOKU_LEXER_EXIT:
53        $handler->addCall('list_close', array(), $pos);
54        $handler->getCallWriter()->process();
55        $ReWriter = $handler->getCallWriter();
56        $handler->setCallWriter($ReWriter->getCallWriter());
57        break;
58      case DOKU_LEXER_MATCHED:
59        $handler->addCall('list_item', array($match), $pos);
60        break;
61      case DOKU_LEXER_UNMATCHED:
62        $handler->addCall('cdata', array($match), $pos);
63        break;
64    }
65    return true;
66  }
67
68  function render($mode, Doku_Renderer $renderer, $data)
69  {
70    return true;
71  }
72}
73
74/* ----- Mediasyntax List Call Writer ----- */
75
76class Doku_Handler_Mediasyntax_List extends \dokuwiki\Parsing\Handler\Lists
77{
78  function interpretSyntax($match, &$type)
79  {
80    $pos=strpos($match,"*");
81    if ($pos===false) $type="o";
82    else $type="u";
83    $level = strlen(trim($match));  // Mediasyntax
84    return $level;
85  }
86}
87
88//Setup VIM: ex: et ts=4 enc=utf-8 :
89