1<?php 2/* 3 * Unorderd lists: 4 * * ... 5 * * ... 6 */ 7 8if(!defined('DOKU_INC')) die(); 9if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 10require_once(DOKU_PLUGIN.'syntax.php'); 11 12use dokuwiki\Parsing\Handler\Lists; 13 14class syntax_plugin_markdowku_ulists extends DokuWiki_Syntax_Plugin { 15 function getType() { return 'container'; } 16 function getPType() { return 'block'; } 17 function getSort() { return 9; } 18 function getAllowedTypes() { 19 return array('formatting', 'substition', 'paragraphs', 'baseonly', 'container'); 20 } 21 22 function connectTo($mode) { 23 /* The negative lookahead is for not conflicting with hrs. */ 24 $this->Lexer->addEntryPattern( 25 '\n\n[ ]{0,3}[*+-][ \t](?!(?:[ ]?[*+-][ ]?){2,}[ \t]*\n)', 26 $mode, 27 'plugin_markdowku_ulists'); 28 29 $this->Lexer->addPattern( 30 '\n[ \t]*[*+-][ \t](?!(?:[ ]?[*+-][ ]?){2,}[ \t]*\n)', 31 'plugin_markdowku_ulists'); 32 } 33 34 function postConnect() { 35 $this->Lexer->addExitPattern( 36 '(?:\Z|\n{1,}(?=\n\S)(?!\n[ \t]*[*+-][ \t]))', 37 'plugin_markdowku_ulists'); 38 } 39 40 function handle($match, $state, $pos, Doku_Handler $handler) { 41 switch ($state) { 42 case DOKU_LEXER_ENTER: 43 $ReWriter = new Doku_Handler_Markdown_Unordered_List($handler->getCallWriter()); 44 $handler->setCallWriter($ReWriter); 45 $handler->_addCall('list_open', array($match), $pos); 46 break; 47 case DOKU_LEXER_MATCHED: 48 $handler->_addCall('list_item', array($match), $pos); 49 break; 50 case DOKU_LEXER_UNMATCHED: 51 $handler->_addCall('cdata', array($match), $pos); 52 break; 53 case DOKU_LEXER_EXIT: 54 $handler->_addCall('list_close', array(), $pos); 55 $handler->getCallWriter()->process(); 56 $ReWriter = & $handler->getCallWriter(); 57 $handler->setCallWriter($ReWriter->getCallWriter()); 58 break; 59 } 60 return true; 61 } 62 63 function render($mode, Doku_Renderer $renderer, $data) { 64 return true; 65 } 66} 67 68class Doku_Handler_Markdown_Unordered_List extends Lists { 69 private $depth = array(0, 4); 70 71 function interpretSyntax($match, &$type) { 72 $type="u"; 73 $listlevel = 1; 74 $real_position = 0; 75 $logical_position = 0; 76 $text = preg_replace('/^\n*/', '', $match); 77 78 while (TRUE) { 79 if (preg_match('/^[ ]{'.$this->depth[$listlevel].'}/', substr($text, $real_position)) > 0) { 80 $real_position += $this->depth[$listlevel]; 81 $logical_position += $this->depth[$listlevel]; 82 $listlevel += 1; 83 continue; 84 } 85 if (preg_match('/^\t/', substr($text, $real_position)) > 0) { 86 $real_position += 1; 87 $logical_position += 4; 88 $listlevel += 1; 89 continue; 90 } 91 if (preg_match('/^[ ]{0,3}[*+-][ \t]/', substr($text, $real_position)) > 0) { 92 $this->depth[$listlevel] = strlen(substr($text, $real_position)) - 1; 93 } 94 break; 95 } 96 return $listlevel + 1; 97 } 98} 99//Setup VIM: ex: et ts=4 enc=utf-8 : 100