diff options
Diffstat (limited to 'platform/www/lib/plugins/markdowku/syntax')
24 files changed, 1320 insertions, 0 deletions
diff --git a/platform/www/lib/plugins/markdowku/syntax/anchorsinline.php b/platform/www/lib/plugins/markdowku/syntax/anchorsinline.php new file mode 100644 index 0000000..b16f2b4 --- /dev/null +++ b/platform/www/lib/plugins/markdowku/syntax/anchorsinline.php @@ -0,0 +1,46 @@ +<?php +/* + * Inline links [name](target "title") + */ + +if(!defined('DOKU_INC')) die(); +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +require_once(DOKU_PLUGIN.'syntax.php'); + +class syntax_plugin_markdowku_anchorsinline extends DokuWiki_Syntax_Plugin { + + function getType() { return 'substition'; } + function getPType() { return 'normal'; } + function getSort() { return 102; } + + function connectTo($mode) { + $this->nested_brackets_re = + str_repeat('(?>[^\[\]]+|\[', 6). + str_repeat('\])*', 6); + $this->Lexer->addSpecialPattern( + '\['.$this->nested_brackets_re.'\]\([ \t]*<?.+?>?[ \t]*(?:[\'"].*?[\'"])?\)', + $mode, + 'plugin_markdowku_anchorsinline' + ); + } + + function handle($match, $state, $pos, Doku_Handler $handler) { + if ($state == DOKU_LEXER_SPECIAL) { + $text = preg_match( + '/^\[('.$this->nested_brackets_re.')\]\([ \t]*<?(.+?)>?[ \t]*(?:[\'"](.*?)[\'"])?[ \t]*?\)$/', + $match, + $matches); + $target = $matches[2] == '' ? $matches[3] : $matches[2]; + $title = $matches[1]; + + $target = preg_replace('/^mailto:/', '', $target); + $handler->internallink($target.'|'.$title, $state, $pos); + } + return true; + } + + function render($mode, Doku_Renderer $renderer, $data) { + return true; + } +} +//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/platform/www/lib/plugins/markdowku/syntax/anchorsreference.php b/platform/www/lib/plugins/markdowku/syntax/anchorsreference.php new file mode 100644 index 0000000..be8cdd6 --- /dev/null +++ b/platform/www/lib/plugins/markdowku/syntax/anchorsreference.php @@ -0,0 +1,62 @@ +<?php +/* + * Reference links, i.e. + * ... [name][id] ... + * ... [id][] ... + * ... + * [id]: http://example.com (handled by markdowku_references) + */ + +if(!defined('DOKU_INC')) die(); +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +require_once(DOKU_PLUGIN.'syntax.php'); + +class syntax_plugin_markdowku_anchorsreference extends DokuWiki_Syntax_Plugin { + + function getType() { return 'substition'; } + function getPType() { return 'normal'; } + function getSort() { return 102; } + + function connectTo($mode) { + $this->nested_brackets_re = + str_repeat('(?>[^\[\]]+|\[', 3). + str_repeat('\])*', 3); + $this->Lexer->addSpecialPattern( + '\['.$this->nested_brackets_re.'\][ ]?(?:\n[ ]*)?\[[^\[\]\n]*?\]', + $mode, + 'plugin_markdowku_anchorsreference'); + } + + function handle($match, $state, $pos, Doku_Handler $handler) { + return array($state, $match); + } + + function render($mode, Doku_Renderer$renderer, $data) { + global $ID; + preg_match( + '/^\[('.$this->nested_brackets_re.')\][ ]?(?:\n[ ]*)?\[(.*?)\]$/', + $data[1], + $matches); + + $title = $matches[1]; + + if ($matches[2] == '') + $rid = $matches[1]; + else + $rid = $matches[2]; + + $rid = preg_replace("/ /", ".", $rid); + $target = p_get_metadata($ID, 'markdowku_references_'.$rid, METADATA_RENDER_USING_CACHE); + if ($target == '') { + $renderer->cdata($data[1]); + } else if (preg_match('/^mailto:/', $target) or + preg_match('<'.PREG_PATTERN_VALID_EMAIL.'>', $target)) { + $target = preg_replace('/^mailto:/', '', $target); + $renderer->emaillink($target, $title); + } else { + $renderer->externallink($target, $title); + } + return true; + } +} +//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/platform/www/lib/plugins/markdowku/syntax/autolinks.php b/platform/www/lib/plugins/markdowku/syntax/autolinks.php new file mode 100644 index 0000000..b6ed523 --- /dev/null +++ b/platform/www/lib/plugins/markdowku/syntax/autolinks.php @@ -0,0 +1,40 @@ +<?php +/* + * Autolinks enclosed in <...> + */ + +if(!defined('DOKU_INC')) die(); +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +require_once(DOKU_PLUGIN.'syntax.php'); + +class syntax_plugin_markdowku_autolinks extends DokuWiki_Syntax_Plugin { + + function getType() { return 'substition'; } + function getPType() { return 'normal'; } + function getSort() { return 102; } + + function connectTo($mode) { + $this->Lexer->addSpecialPattern( + '<(?:https?|ftp|mailto):[^\'">\s]+?>', + $mode, + 'plugin_markdowku_autolinks' + ); + } + + function handle($match, $state, $pos, Doku_Handler $handler) { + if (preg_match('/^<mailto:/', $match)) { + $match = substr($match, 8, -1); + $handler->_addCall('emaillink', array($match, NULL), $pos); + } else { + $match = substr($match, 1, -1); + $handler->_addCall('externallink', array($match, NULL), $pos); + } + + return true; + } + + function render($mode, Doku_Renderer $renderer, $data) { + return true; + } +} +//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/platform/www/lib/plugins/markdowku/syntax/blockquotes.php b/platform/www/lib/plugins/markdowku/syntax/blockquotes.php new file mode 100644 index 0000000..463c049 --- /dev/null +++ b/platform/www/lib/plugins/markdowku/syntax/blockquotes.php @@ -0,0 +1,115 @@ +<?php + +if(!defined('DOKU_INC')) die(); +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +require_once(DOKU_PLUGIN.'syntax.php'); +include_once('headeratx.php'); + +use dokuwiki\Parsing\Handler\Quote; + +class syntax_plugin_markdowku_blockquotes extends DokuWiki_Syntax_Plugin { + + function getType() { return 'container'; } + function getPType() { return 'block'; } + function getSort() { return 219; } + function getAllowedTypes() { + return array('formatting', 'substition', 'disabled', 'protected', + 'container'); + } + + function connectTo($mode) { + $this->Lexer->addEntryPattern( + // (?<=\n)[ \t]*>[ \t]?(?=(?:\n[ ]*[^>]|\Z)) +// '\n[ \t]*>[ \t]?.+?\n(?:.+\n)*', +// '(?:\n|\A)[ \t]*>(?:[ >\t]*)?', //[ \t]?(?=[^\n]+?\n)', + '(?:\n|\A)[ \t]*>(?:[ >\t]*)?.*?(?=\n)', //[ \t]?(?=[^\n]+?\n)', + $mode, + 'plugin_markdowku_blockquotes'); + + /* Setext headers need two lines */ + $this->Lexer->addPattern( + '\n[ \t]*>(?:[ \t>]*>)?[ \t]?[^\n]+?[ \t]*\n[ \t]*>(?:[ \t>]*>)?[ \t]?=+[ \t]*', + 'plugin_markdowku_blockquotes'); + + $this->Lexer->addPattern( + '\n[ \t]*>(?:[ \t>]*>)?[ \t]?[^\n]+?[ \t]*\n[ \t]*>(?:[ \t>]*>)?[ \t]?-+[ \t]*', + 'plugin_markdowku_blockquotes'); + + $this->Lexer->addPattern( +// '\n[ \t]*>(?:[ \t>]*>)?[ \t]?', //[ \t]?(?=[^\n]+?\n)', + '\n[ \t]*>(?:[ \t>]*>)?[ \t]?.*?(?=\n)', //[ \t]?(?=[^\n]+?\n)', + 'plugin_markdowku_blockquotes'); + } + + function postConnect() { + $this->Lexer->addExitPattern( + '(?:\n[^>]|\Z)', + 'plugin_markdowku_blockquotes'); + } + + function handle($match, $state, $pos, Doku_Handler $handler) { + global $DOKU_PLUGINS; + + preg_match('/^\n[ \t]*>(?:[ \t>]*>)?[ \t]?/', $match, $quotearg); + $quoteinarg = preg_replace('/^\n[ \t]*>(?:[ \t>]*>)?[ \t]?/', '', $match); + + if ($state == DOKU_LEXER_ENTER) { + $ReWriter = new Doku_Handler_Markdown_Quote($handler->getCallWriter()); + $handler->setCallWriter($ReWriter); + $handler->_addCall('quote_start', $quotearg, $pos); + } elseif ($state == DOKU_LEXER_EXIT) { + $handler->_addCall('quote_end', array(), $pos); + $handler->getCallWriter()->process(); + $ReWriter = & $handler->getCallWriter(); + $handler->setCallWriter($ReWriter->getCallWriter()); + } + + if ($quoteinarg == '') { + $handler->_addCall('quote_newline', $quotearg, $pos); + /* ATX headers (headeratx) */ + } elseif (preg_match('/^\#{1,6}[ \t]*.+?[ \t]*\#*/', $quoteinarg)) { + $plugin =& plugin_load('syntax', 'markdowku_headeratx'); + $plugin->handle($quoteinarg, $state, $pos, $handler); + /* Horizontal rulers (hr) */ + } elseif (preg_match('/[ ]{0,2}(?:[ ]?_[ ]?){3,}[ \t]*/', $quoteinarg) + or preg_match('/[ ]{0,2}(?:[ ]?-[ ]?){3,}[ \t]*/', $quoteinarg) + or preg_match('/[ ]{0,2}(?:[ ]?\*[ ]?){3,}[ \t]*/', $quoteinarg)) { + $plugin =& plugin_load('syntax', 'markdowku_hr'); + $plugin->handle($quoteinarg, $state, $pos, $handler); + /* Setext headers (headersetext) */ + } elseif (preg_match('/^[^\n]+?[ \t]*\n[ \t]*>(?:[ \t>]*>)?[ \t]?=+[ \t]*/', $quoteinarg) + or preg_match('/^[^\n]+?[ \t]*\n[ \t]*>(?:[ \t>]*>)?[ \t]?-+[ \t]*/', $quoteinarg)) { + $quoteinarg = preg_replace('/(?<=\n)[ \t]*>(?:[ \t>]*>)?[ \t]?/', '', $quoteinarg); + $plugin =& plugin_load('syntax', 'markdowku_headersetext'); + $plugin->handle($quoteinarg, $state, $pos, $handler); + } else { + $handler->_addCall('cdata', array($quoteinarg), $pos); + } + + return true; + } + + function render($mode, Doku_Renderer $renderer, $data) { + return true; + } +} + +class Doku_Handler_Markdown_Quote extends Quote { + function getDepth($marker) { + $quoteLength = 0; + $position = 0; + $text = preg_replace('/^\n*/', '', $marker); + while (TRUE) { + if (preg_match('/^[ \t]/', substr($text, $position)) > 0) { + $position++; + } elseif (preg_match('/^>/', substr($text, $position)) > 0) { + $position++; + $quoteLength++; + } else { + break; + } + } + return $quoteLength; + } +} +//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/platform/www/lib/plugins/markdowku/syntax/boldasterisk.php b/platform/www/lib/plugins/markdowku/syntax/boldasterisk.php new file mode 100644 index 0000000..0dcad52 --- /dev/null +++ b/platform/www/lib/plugins/markdowku/syntax/boldasterisk.php @@ -0,0 +1,45 @@ +<?php +/* + * Bold text enclosed in asterisks: **...** + */ + +if(!defined('DOKU_INC')) die(); +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +require_once(DOKU_PLUGIN.'syntax.php'); + +class syntax_plugin_markdowku_boldasterisk extends DokuWiki_Syntax_Plugin { + + function getType() { return 'formatting'; } + function getPType() { return 'normal'; } + function getSort() { return 69; } + function getAllowedTypes() { return array('formatting', 'substition'); } + + function connectTo($mode) { + $this->Lexer->addEntryPattern( + '(?<![\\\\*])\*\*(?![ ])(?=(?:(?!\n\n).)+?[^\\\\ ]\*\*)', + $mode, + 'plugin_markdowku_boldasterisk'); + } + + function postConnect() { + $this->Lexer->addExitPattern( + '(?<![\\\\ ])\*\*', + 'plugin_markdowku_boldasterisk'); + } + + function handle($match, $state, $pos, Doku_Handler $handler) { + return array($state, $match); + } + + function render($mode, Doku_Renderer $renderer, $data) { + if ($data[0] == DOKU_LEXER_ENTER) + $renderer->strong_open(); + elseif ($data[0] == DOKU_LEXER_EXIT) + $renderer->strong_close(); + else + $renderer->cdata($data[1]); + + return true; + } +} +//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/platform/www/lib/plugins/markdowku/syntax/codeblocks.php b/platform/www/lib/plugins/markdowku/syntax/codeblocks.php new file mode 100644 index 0000000..bbda567 --- /dev/null +++ b/platform/www/lib/plugins/markdowku/syntax/codeblocks.php @@ -0,0 +1,63 @@ +<?php +/* + * Codeblocks, indented by four spaces + */ + +if(!defined('DOKU_INC')) die(); +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +require_once(DOKU_PLUGIN.'syntax.php'); + +use dokuwiki\Parsing\Handler\Preformatted; + +class syntax_plugin_markdowku_codeblocks extends DokuWiki_Syntax_Plugin { + + function getType() { return 'protected'; } + function getPType() { return 'block'; } + function getSort() { return 199; } + + function connectTo($mode) { + $this->Lexer->addEntryPattern( + '(?:\n\n|\A\n?) ', + $mode, + 'plugin_markdowku_codeblocks'); + + $this->Lexer->addPattern( + '\n ', + 'plugin_markdowku_codeblocks'); + } + + function postConnect() { + $this->Lexer->addExitPattern( + '\n(?:(?=\n*[ ]{0,3}\S)|\Z)', + 'plugin_markdowku_codeblocks'); + } + + function handle($match, $state, $pos, Doku_Handler $handler) { + switch ($state) { + case DOKU_LEXER_ENTER: + $ReWriter = new Preformatted($handler->getCallWriter()); + $handler->setCallWriter($ReWriter); + $handler->_addCall('preformatted_start', array($match), $pos); + break; + case DOKU_LEXER_MATCHED: + $handler->_addCall('preformatted_newline', array($match), $pos); + break; + case DOKU_LEXER_UNMATCHED: + $handler->_addCall('preformatted_content', array($match), $pos); + break; + case DOKU_LEXER_EXIT: + $handler->_addCall('preformatted_end', array(), $pos); + $handler->_addCall('preformatted_content', array($match), $pos); + $handler->getCallWriter()->process(); + $ReWriter = & $handler->getCallWriter(); + $handler->setCallWriter($ReWriter->getCallWriter()); + break; + } + return true; + } + + function render($mode, Doku_Renderer $renderer, $data) { + return false; + } +} +//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/platform/www/lib/plugins/markdowku/syntax/codespans1.php b/platform/www/lib/plugins/markdowku/syntax/codespans1.php new file mode 100644 index 0000000..6465288 --- /dev/null +++ b/platform/www/lib/plugins/markdowku/syntax/codespans1.php @@ -0,0 +1,35 @@ +<?php +/* + * Codespans enclosed with one backtick: `...` + */ + +if(!defined('DOKU_INC')) die(); +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +require_once(DOKU_PLUGIN.'syntax.php'); + +class syntax_plugin_markdowku_codespans1 extends DokuWiki_Syntax_Plugin { + + function getType() { return 'formatting'; } + function getPType() { return 'normal'; } + function getSort() { return 99; } + function getAllowedTypes() { return array(); } + + function connectTo($mode) { + $this->Lexer->addSpecialPattern( + '(?<!`)`(?!`).+?(?<!`)`(?!`)', + $mode, + 'plugin_markdowku_codespans1'); + } + + function handle($match, $state, $pos, Doku_Handler $handler) { + return array($match); + } + + function render($mode, Doku_Renderer $renderer, $data) { + $renderer->monospace_open(); + $renderer->cdata(substr($data[0], 1, -1)); + $renderer->monospace_close(); + return true; + } +} +//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/platform/www/lib/plugins/markdowku/syntax/codespans2.php b/platform/www/lib/plugins/markdowku/syntax/codespans2.php new file mode 100644 index 0000000..596fc28 --- /dev/null +++ b/platform/www/lib/plugins/markdowku/syntax/codespans2.php @@ -0,0 +1,34 @@ +<?php +/* + * Codespans enclosed with two backticks: ``...`` + */ + +if(!defined('DOKU_INC')) die(); +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +require_once(DOKU_PLUGIN.'syntax.php'); + +class syntax_plugin_markdowku_codespans2 extends DokuWiki_Syntax_Plugin { + + function getType() { return 'formatting'; } + function getPType() { return 'normal'; } + function getSort() { return 98; } + + function connectTo($mode) { + $this->Lexer->addSpecialPattern( + '(?<!`)``(?!`).+?(?<!`)``(?!`)', + $mode, + 'plugin_markdowku_codespans2'); + } + + function handle($match, $state, $pos, Doku_Handler $handler) { + return array($match); + } + + function render($mode, Doku_Renderer $renderer, $data) { + $renderer->monospace_open(); + $renderer->cdata(substr($data[0], 2, -2)); + $renderer->monospace_close(); + return true; + } +} +//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/platform/www/lib/plugins/markdowku/syntax/codespans3.php b/platform/www/lib/plugins/markdowku/syntax/codespans3.php new file mode 100644 index 0000000..b6b342b --- /dev/null +++ b/platform/www/lib/plugins/markdowku/syntax/codespans3.php @@ -0,0 +1,34 @@ +<?php +/* + * Codespans enclosed within three backticks: ```...``` + */ + +if(!defined('DOKU_INC')) die(); +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +require_once(DOKU_PLUGIN.'syntax.php'); + +class syntax_plugin_markdowku_codespans3 extends DokuWiki_Syntax_Plugin { + + function getType() { return 'formatting'; } + function getPType() { return 'normal'; } + function getSort() { return 97; } + + function connectTo($mode) { + $this->Lexer->addSpecialPattern( + '(?<!`)```(?!`).+?(?<!`)```(?!`)', + $mode, + 'plugin_markdowku_codespans3'); + } + + function handle($match, $state, $pos, Doku_Handler $handler) { + return array($match); + } + + function render($mode, Doku_Renderer $renderer, $data) { + $renderer->monospace_open(); + $renderer->cdata(substr($data[0], 3, -3)); + $renderer->monospace_close(); + return true; + } +} +//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/platform/www/lib/plugins/markdowku/syntax/codespans4.php b/platform/www/lib/plugins/markdowku/syntax/codespans4.php new file mode 100644 index 0000000..4166d7f --- /dev/null +++ b/platform/www/lib/plugins/markdowku/syntax/codespans4.php @@ -0,0 +1,34 @@ +<?php +/* + * Codespans enclosed within four backticks: ````...```` + */ + +if(!defined('DOKU_INC')) die(); +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +require_once(DOKU_PLUGIN.'syntax.php'); + +class syntax_plugin_markdowku_codespans4 extends DokuWiki_Syntax_Plugin { + + function getType() { return 'formatting'; } + function getPType() { return 'normal'; } + function getSort() { return 96; } + + function connectTo($mode) { + $this->Lexer->addSpecialPattern( + '(?<!`)````(?!`).+?(?<!`)````(?!`)', + $mode, + 'plugin_markdowku_codespans4'); + } + + function handle($match, $state, $pos, Doku_Handler $handler) { + return array($match); + } + + function render($mode, Doku_Renderer $renderer, $data) { + $renderer->monospace_open(); + $renderer->cdata(substr($data[0], 4, -4)); + $renderer->monospace_close(); + return true; + } +} +//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/platform/www/lib/plugins/markdowku/syntax/codespans5.php b/platform/www/lib/plugins/markdowku/syntax/codespans5.php new file mode 100644 index 0000000..00f33d2 --- /dev/null +++ b/platform/www/lib/plugins/markdowku/syntax/codespans5.php @@ -0,0 +1,34 @@ +<?php +/* + * Codespans enclosed within five brackets: `````...````` + */ + +if(!defined('DOKU_INC')) die(); +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +require_once(DOKU_PLUGIN.'syntax.php'); + +class syntax_plugin_markdowku_codespans5 extends DokuWiki_Syntax_Plugin { + + function getType() { return 'formatting'; } + function getPType() { return 'normal'; } + function getSort() { return 95; } + + function connectTo($mode) { + $this->Lexer->addSpecialPattern( + '(?<!`)`````(?!`).+?(?<!`)`````(?!`)', + $mode, + 'plugin_markdowku_codespans5'); + } + + function handle($match, $state, $pos, Doku_Handler $handler) { + return array($match); + } + + function render($mode, Doku_Renderer $renderer, $data) { + $renderer->monospace_open(); + $renderer->cdata(substr($data[0], 5, -5)); + $renderer->monospace_close(); + return true; + } +} +//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/platform/www/lib/plugins/markdowku/syntax/escapespecialchars.php b/platform/www/lib/plugins/markdowku/syntax/escapespecialchars.php new file mode 100644 index 0000000..b27b7c0 --- /dev/null +++ b/platform/www/lib/plugins/markdowku/syntax/escapespecialchars.php @@ -0,0 +1,94 @@ +<?php +/* + * Unescape escaped backslash. \\\\ -> \ + * This is in a separate class as it needs a higher priority than the other + * escapes. + */ + +if(!defined('DOKU_INC')) die(); +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +require_once(DOKU_PLUGIN.'syntax.php'); + +class syntax_plugin_markdowku_escapespecialchars extends DokuWiki_Syntax_Plugin { + + function getType() { return 'substition'; } + function getPType() { return 'normal'; } + function getSort() { return 61; } + + function connectTo($mode) { + $this->Lexer->addSpecialPattern( + '(?<!\\\\)\\\\`', + $mode, + 'plugin_markdowku_escapespecialchars'); + $this->Lexer->addSpecialPattern( + '(?<!\\\\)\\\\\*', + $mode, + 'plugin_markdowku_escapespecialchars'); + $this->Lexer->addSpecialPattern( + '(?<!\\\\)\\\\_', + $mode, + 'plugin_markdowku_escapespecialchars'); + $this->Lexer->addSpecialPattern( + '(?<!\\\\)\\\\\{', + $mode, + 'plugin_markdowku_escapespecialchars'); + $this->Lexer->addSpecialPattern( + '(?<!\\\\)\\\\\}', + $mode, + 'plugin_markdowku_escapespecialchars'); + $this->Lexer->addSpecialPattern( + '(?<!\\\\)\\\\\[', + $mode, + 'plugin_markdowku_escapespecialchars'); + $this->Lexer->addSpecialPattern( + '(?<!\\\\)\\\\\]', + $mode, + 'plugin_markdowku_escapespecialchars'); + $this->Lexer->addSpecialPattern( + '(?<!\\\\)\\\\\(', + $mode, + 'plugin_markdowku_escapespecialchars'); + $this->Lexer->addSpecialPattern( + '(?<!\\\\)\\\\\)', + $mode, + 'plugin_markdowku_escapespecialchars'); + $this->Lexer->addSpecialPattern( + '(?<!\\\\)\\\\>', + $mode, + 'plugin_markdowku_escapespecialchars'); + $this->Lexer->addSpecialPattern( + '(?<!\\\\)\\\\\#', + $mode, + 'plugin_markdowku_escapespecialchars'); + $this->Lexer->addSpecialPattern( + '(?<!\\\\)\\\\\+', + $mode, + 'plugin_markdowku_escapespecialchars'); + $this->Lexer->addSpecialPattern( + '(?<!\\\\)\\\\\-', + $mode, + 'plugin_markdowku_escapespecialchars'); + $this->Lexer->addSpecialPattern( + '(?<!\\\\)\\\\\-', + $mode, + 'plugin_markdowku_escapespecialchars'); + $this->Lexer->addSpecialPattern( + '(?<!\\\\)\\\\\.', + $mode, + 'plugin_markdowku_escapespecialchars'); + $this->Lexer->addSpecialPattern( + '(?<!\\\\)\\\\!', + $mode, + 'plugin_markdowku_escapespecialchars'); + } + + function handle($match, $state, $pos, Doku_Handler $handler) { + return array($state, $match); + } + + function render($mode, Doku_Renderer $renderer, $data) { + $renderer->doc .= substr($data[1], -1); + return true; + } +} +//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/platform/www/lib/plugins/markdowku/syntax/githubcodeblocks.php b/platform/www/lib/plugins/markdowku/syntax/githubcodeblocks.php new file mode 100644 index 0000000..c715c55 --- /dev/null +++ b/platform/www/lib/plugins/markdowku/syntax/githubcodeblocks.php @@ -0,0 +1,48 @@ +<?php +/* + * Github style codeblocks, starting and ending with three backticks, optionally + * providing a language to be used for syntax highlighting. + * + * ```php + * ... + * ``` + */ + +if(!defined('DOKU_INC')) die(); +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +require_once(DOKU_PLUGIN.'syntax.php'); + +class syntax_plugin_markdowku_githubcodeblocks extends DokuWiki_Syntax_Plugin { + + function getType() { return 'protected'; } + function getPType() { return 'block'; } + function getSort() { return 91; } + + function connectTo($mode) { + $this->Lexer->addSpecialPattern( + '\n```[a-z0-9_]*\n.+?\n```(?=\n)', + $mode, + 'plugin_markdowku_githubcodeblocks'); + } + + function handle($match, $state, $pos, Doku_Handler $handler) { + if (preg_match('/^\n```([a-z0-9_]+)\n/', $match, $matches) > 0) { + $lang = $matches[1]; + } else { + $lang = NULL; + } + + $text = preg_replace('/^```[a-z0-9_]+\n/m', '', $match); + $text = preg_replace('/^```$/m', '', $text); + if ($lang) + $handler->_addCall('file', array($text, $lang, 'snippet.'.$lang), $pos); + else + $handler->_addCall('code', array($text, $lang), $pos); + return true; + } + + function render($mode, Doku_Renderer $renderer, $data) { + return true; + } +} +//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/platform/www/lib/plugins/markdowku/syntax/headeratx.php b/platform/www/lib/plugins/markdowku/syntax/headeratx.php new file mode 100644 index 0000000..b55c38c --- /dev/null +++ b/platform/www/lib/plugins/markdowku/syntax/headeratx.php @@ -0,0 +1,57 @@ +<?php +/* + * Header in ATX style, i.e. '# Header1', '## Header2', ... + */ + +if (!defined('DOKU_INC')) die(); +if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/'); +require_once (DOKU_PLUGIN . 'syntax.php'); + +class syntax_plugin_markdowku_headeratx extends DokuWiki_Syntax_Plugin { + + function getType() { return 'baseonly'; } + function getPType() { return 'block'; } + function getSort() { return 49; } + function getAllowedTypes() { + return array('formatting', 'substition', 'disabled', 'protected'); + } + + function connectTo($mode) { + $this->Lexer->addSpecialPattern( + '\n\#{1,6}[ \t]*.+?[ \t]*\#*(?=\n+)', + 'base', + 'plugin_markdowku_headeratx'); + } + + function handle($match, $state, $pos, Doku_Handler $handler) { + global $conf; + + $title = trim($match); + $level = strspn($title, '#'); + $title = trim($title, '#'); + $title = trim($title); + + if ($level < 1) + $level = 1; + elseif ($level > 6) + $level = 6; + + if ($handler->getStatus('section')) + $handler->_addCall('section_close', array(), $pos); + if ($level <= $conf['maxseclevel']) { + $handler->setStatus('section_edit_start', $pos); + $handler->setStatus('section_edit_level', $level); + $handler->setStatus('section_edit_title', $title); + } + $handler->_addCall('header', array($title, $level, $pos), $pos); + $handler->_addCall('section_open', array($level), $pos); + $handler->setStatus('section', true); + + return true; + } + + function render($mode, Doku_Renderer $renderer, $data) { + return true; + } +} +//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/platform/www/lib/plugins/markdowku/syntax/headersetext.php b/platform/www/lib/plugins/markdowku/syntax/headersetext.php new file mode 100644 index 0000000..43e9551 --- /dev/null +++ b/platform/www/lib/plugins/markdowku/syntax/headersetext.php @@ -0,0 +1,56 @@ +<?php +/* + * Setext style headers: + * Header + * ====== + */ + +if (!defined('DOKU_INC')) die(); +if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/'); +require_once (DOKU_PLUGIN . 'syntax.php'); + +class syntax_plugin_markdowku_headersetext extends DokuWiki_Syntax_Plugin { + + function getType() { return 'baseonly'; } + function getPType() { return 'block'; } + function getSort() { return 49; } + function getAllowedTypes() { + return array('formatting', 'substition', 'disabled', 'protected'); + } + + function connectTo($mode) { + $this->Lexer->addSpecialPattern( + '\n[^\n]+[ \t]*\n=+[ \t]*(?=\n)', + 'base', + 'plugin_markdowku_headersetext'); + + $this->Lexer->addSpecialPattern( + '\n[^\n]+[ \t]*\n-+[ \t]*(?=\n)', + 'base', + 'plugin_markdowku_headersetext'); + } + + function handle($match, $state, $pos, Doku_Handler $handler) { + $title = preg_replace('/^\n(.+?)[ \t]*\n.*/', '\1', $match); + $title = trim($title); + if (preg_match('/^\n(.+?)[ \t]*\n=/', $match)) + $level = 1; + if (preg_match('/^\n(.+?)[ \t]*\n-/', $match)) + $level = 2; + + if ($handler->getStatus('section')) + $handler->_addCall('section_close', array(), $pos); + $handler->setStatus('section_edit_start', $pos); + $handler->setStatus('section_edit_level', $level); + $handler->setStatus('section_edit_title', $title); + $handler->_addCall('header', array($title, $level, $pos), $pos); + $handler->_addCall('section_open', array($level), $pos); + $handler->setStatus('section', true); + return true; + } + + function render($mode, Doku_Renderer $renderer, $data) { + return true; + } +} +//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/platform/www/lib/plugins/markdowku/syntax/hr.php b/platform/www/lib/plugins/markdowku/syntax/hr.php new file mode 100644 index 0000000..f9da2c0 --- /dev/null +++ b/platform/www/lib/plugins/markdowku/syntax/hr.php @@ -0,0 +1,47 @@ +<?php +/* + * Horizontal rulers: + * * * * + * --- + * ___ + */ + +if(!defined('DOKU_INC')) die(); +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +require_once(DOKU_PLUGIN.'syntax.php'); + +class syntax_plugin_markdowku_hr extends DokuWiki_Syntax_Plugin { + + function getType() { return 'container'; } + function getPType() { return 'block'; } + function getSort() { return 8; } /* Before list block parsing. */ + + function connectTo($mode) { + /* We use two newlines, as we don't want to conflict with setext header + * parsing, but also have to be before list blocks. */ + $this->Lexer->addSpecialPattern( + '\n[ ]{0,2}(?:[ ]?\*[ ]?){3,}[ \t]*(?=\n)', + $mode, + 'plugin_markdowku_hr'); + + $this->Lexer->addSpecialPattern( + '\n[ ]{0,2}(?:[ ]?-[ ]?){3,}[ \t]*(?=\n)', + $mode, + 'plugin_markdowku_hr'); + + $this->Lexer->addSpecialPattern( + '\n[ ]{0,2}(?:[ ]?_[ ]?){3,}[ \t]*(?=\n)', + $mode, + 'plugin_markdowku_hr'); + } + + function handle($match, $state, $pos, Doku_Handler $handler) { + $handler->_addCall('hr', array(), $pos); + return true; + } + + function render($mode, Doku_Renderer $renderer, $data) { + return true; + } +} +//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/platform/www/lib/plugins/markdowku/syntax/imagesinline.php b/platform/www/lib/plugins/markdowku/syntax/imagesinline.php new file mode 100644 index 0000000..28b7d75 --- /dev/null +++ b/platform/www/lib/plugins/markdowku/syntax/imagesinline.php @@ -0,0 +1,43 @@ +<?php +/* + * Inline images: ![source](description "title") + */ + +if(!defined('DOKU_INC')) die(); +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +require_once(DOKU_PLUGIN.'syntax.php'); + +class syntax_plugin_markdowku_imagesinline extends DokuWiki_Syntax_Plugin { + + function getType() { return 'substition'; } + function getPType() { return 'block'; } + function getSort() { return 101; } + + function connectTo($mode) { + $this->nested_brackets_re = + str_repeat('(?>[^\[\]]+|\[', 6). + str_repeat('\])*', 6); + $this->Lexer->addSpecialPattern( + '\!\['.$this->nested_brackets_re.'\]\([ \t]*<?.+?>?[ \t]*(?:[\'"].*?[\'"])?\)', + $mode, + 'plugin_markdowku_imagesinline'); + } + + function handle($match, $state, $pos, Doku_Handler $handler) { + if ($state == DOKU_LEXER_SPECIAL) { + $text = preg_match( + '/^\!\[('.$this->nested_brackets_re.')\]\([ \t]*<?(.+?)>?[ \t]*(?:[\'"](.*?)[\'"])?[ \t]*?\)$/', + $match, + $matches); + $target = $matches[2] == '' ? $matches[3] : $matches[2]; + $title = $matches[1]; + $handler->media($target.'|'.$title, $state, $pos); + } + return true; + } + + function render($mode, Doku_Renderer $renderer, $data) { + return true; + } +} +//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/platform/www/lib/plugins/markdowku/syntax/imagesreference.php b/platform/www/lib/plugins/markdowku/syntax/imagesreference.php new file mode 100644 index 0000000..9382d2a --- /dev/null +++ b/platform/www/lib/plugins/markdowku/syntax/imagesreference.php @@ -0,0 +1,58 @@ +<?php +/* + * Reference links, i.e. + * ... [name][id] ... + * ... [id][] ... + * ... + * [id]: http://example.com (handled by markdowku_references) + */ + +if(!defined('DOKU_INC')) die(); +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +require_once(DOKU_PLUGIN.'syntax.php'); + +class syntax_plugin_markdowku_imagesreference extends DokuWiki_Syntax_Plugin { + + function getType() { return 'substition'; } + function getPType() { return 'normal'; } + function getSort() { return 102; } + + function connectTo($mode) { + $this->nested_brackets_re = + str_repeat('(?>[^\[\]]+|\[', 3). + str_repeat('\])*', 3); + $this->Lexer->addSpecialPattern( + '\!\['.$this->nested_brackets_re.'\][ ]?(?:\n[ ]*)?\[[^\n]*?\]', + $mode, + 'plugin_markdowku_imagesreference'); + } + + function handle($match, $state, $pos, Doku_Handler $handler) { + return array($state, $match); + } + + function render($mode, Doku_Renderer $renderer, $data) { + global $ID; + preg_match( + '/^\!\[('.$this->nested_brackets_re.')\][ ]?(?:\n[ ]*)?\[(.*?)\]$/', + $data[1], + $matches); + + $title = $matches[1]; + + if ($matches[2] == '') + $rid = $matches[1]; + else + $rid = $matches[2]; + + $rid = preg_replace("/ /", ".", $rid); + $target = p_get_metadata($ID, 'markdowku_references_'.$rid, METADATA_RENDER_USING_CACHE); + if ($target == '') + $renderer->cdata($data[1]); + else + $renderer->_media($target, $title); + + return true; + } +} +//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/platform/www/lib/plugins/markdowku/syntax/italicasterisk.php b/platform/www/lib/plugins/markdowku/syntax/italicasterisk.php new file mode 100644 index 0000000..bebc45f --- /dev/null +++ b/platform/www/lib/plugins/markdowku/syntax/italicasterisk.php @@ -0,0 +1,49 @@ +<?php +/* + * Italic text enclosed by asterisks, i.e. *...* + */ + +if(!defined('DOKU_INC')) die(); +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +require_once(DOKU_PLUGIN.'syntax.php'); + +# Fix for Hogfather RC2 - see https://github.com/dwp-forge/columns/issues/5#issuecomment-638467603 +require_once(DOKU_INC.'inc/Parsing/Lexer/Lexer.php'); + +class syntax_plugin_markdowku_italicasterisk extends DokuWiki_Syntax_Plugin { + + function getType() { return 'formatting'; } + function getPType() { return 'normal'; } + function getSort() { return 79; } + function getAllowedTypes() { + return Array('formatting', 'substition'); + } + + function connectTo($mode) { + $this->Lexer->addEntryPattern( + '(?<![\\\\])\*(?![ *])(?=(?:(?!\n\n).)+?(?<![\\\\ *])\*)', + $mode, + 'plugin_markdowku_italicasterisk'); + } + + function postConnect() { + $this->Lexer->addExitPattern( + '(?<![\\\\* ])\*', + 'plugin_markdowku_italicasterisk'); + } + + function handle($match, $state, $pos, Doku_Handler $handler) { + return array($state, $match); + } + + function render($mode, Doku_Renderer $renderer, $data) { + if ($data[0] == DOKU_LEXER_ENTER) + $renderer->emphasis_open(); + elseif ($data[0] == DOKU_LEXER_EXIT) + $renderer->emphasis_close(); + else + $renderer->cdata($data[1]); + + return true; + } +} diff --git a/platform/www/lib/plugins/markdowku/syntax/italicunderline.php b/platform/www/lib/plugins/markdowku/syntax/italicunderline.php new file mode 100644 index 0000000..13a5a02 --- /dev/null +++ b/platform/www/lib/plugins/markdowku/syntax/italicunderline.php @@ -0,0 +1,56 @@ +<?php +/* + * Italic text enclosed in underlines: _..._ + */ + +if(!defined('DOKU_INC')) die(); +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +require_once(DOKU_PLUGIN.'syntax.php'); + +# Fix for Hogfather RC2 - see https://github.com/dwp-forge/columns/issues/5#issuecomment-638467603 +require_once(DOKU_INC.'inc/Parsing/Lexer/Lexer.php'); + +class syntax_plugin_markdowku_italicunderline extends DokuWiki_Syntax_Plugin { + + function getType() { return 'formatting'; } + function getPType() { return 'normal'; } + function getSort() { return 79; } + function getAllowedTypes() { + return Array('formatting', 'substition'); + } + + function connectTo($mode) { + $this->Lexer->addEntryPattern( + '(?<![\\\\])_(?![ _])(?=(?:(?!\n\n).)+?[^\\\\ _]_)', + $mode, + 'plugin_markdowku_italicunderline'); +// $this->Lexer->addSpecialPattern( +// '\w+_\w+_\w[\w_]*', +// $mode, +// 'plugin_markdowku_italicunderline'); + } + + function postConnect() { + $this->Lexer->addExitPattern( + '(?<![\\\\_ ])_', + 'plugin_markdowku_italicunderline'); + } + + function handle($match, $state, $pos, Doku_Handler $handler) { + return array($state, $match); + } + + function render($mode, Doku_Renderer $renderer, $data) { + + if ($data[0] == DOKU_LEXER_ENTER) + $renderer->emphasis_open(); + elseif ($data[0] == DOKU_LEXER_EXIT) + $renderer->emphasis_close(); + elseif ($data[0] == DOKU_LEXER_UNMATCHED) + $renderer->cdata($data[1]); + elseif ($data[0] == DOKU_LEXER_SPECIAL) + $renderer->cdata($data[1]); + + return true; + } +} diff --git a/platform/www/lib/plugins/markdowku/syntax/linebreak.php b/platform/www/lib/plugins/markdowku/syntax/linebreak.php new file mode 100644 index 0000000..ef2f1df --- /dev/null +++ b/platform/www/lib/plugins/markdowku/syntax/linebreak.php @@ -0,0 +1,32 @@ +<?php +/* + * Linebreaks, determined by two spaces at the line end. + */ + +if(!defined('DOKU_INC')) die(); +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +require_once(DOKU_PLUGIN.'syntax.php'); + +class syntax_plugin_markdowku_linebreak extends DokuWiki_Syntax_Plugin { + + function getType() { return 'substition'; } + function getPType() { return 'normal'; } + function getSort() { return 139; } + + function connectTo($mode) { + $this->Lexer->addSpecialPattern( + '[ ]{2,}\n', + $mode, + 'plugin_markdowku_linebreak'); + } + + function handle($match, $state, $pos, Doku_Handler $handler) { + return array($match, $state, $pos); + } + + function render($mode, Doku_Renderer $renderer, $data) { + $renderer->linebreak(); + return true; + } +} +//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/platform/www/lib/plugins/markdowku/syntax/olists.php b/platform/www/lib/plugins/markdowku/syntax/olists.php new file mode 100644 index 0000000..853232a --- /dev/null +++ b/platform/www/lib/plugins/markdowku/syntax/olists.php @@ -0,0 +1,98 @@ +<?php +/* + * Ordered lists: + * 1. ... + * 2. ... + */ + +if(!defined('DOKU_INC')) die(); +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +require_once(DOKU_PLUGIN.'syntax.php'); + +use dokuwiki\Parsing\Handler\Lists; + +class syntax_plugin_markdowku_olists extends DokuWiki_Syntax_Plugin { + function getType() { return 'container'; } + function getPType() { return 'block'; } + function getSort() { return 9; } + function getAllowedTypes() { + return array('formatting', 'substition', 'paragraphs', 'baseonly'); + } + + function connectTo($mode) { + $this->Lexer->addEntryPattern( + '\n\n[ ]{0,3}\d+\.[ \t]', + $mode, + 'plugin_markdowku_olists'); + + $this->Lexer->addPattern( + '\n^[ \t]*\d+\.[ \t]', + 'plugin_markdowku_olists'); + } + + function postConnect() { + $this->Lexer->addExitPattern( + '(?:\Z|\n{1,}(?=\n\S)(?!\n[ \t]*\d+\.[ \t]))', + 'plugin_markdowku_olists'); + } + + function handle($match, $state, $pos, Doku_Handler $handler) { + switch ($state) { + case DOKU_LEXER_ENTER: + $ReWriter = new Doku_Handler_Markdown_Ordered_List($handler->getCallWriter()); + $handler->setCallWriter($ReWriter); + $handler->_addCall('list_open', array($match), $pos); + break; + case DOKU_LEXER_MATCHED: + $handler->_addCall('list_item', array($match), $pos); + break; + case DOKU_LEXER_UNMATCHED: + $handler->_addCall('cdata', array($match), $pos); + break; + case DOKU_LEXER_EXIT: + $handler->_addCall('list_close', array(), $pos); + $handler->getCallWriter()->process(); + $ReWriter = & $handler->getCallWriter(); + $handler->setCallWriter($ReWriter->getCallWriter()); + break; + } + return true; + } + + function render($mode, Doku_Renderer $renderer, $data) { + return true; + } +} + +class Doku_Handler_Markdown_Ordered_List extends Lists { + private $depth = array(0, 4); + + function interpretSyntax($match, &$type) { + $type="o"; + $listlevel = 1; + $real_position = 0; + $logical_position = 0; + $text = preg_replace('/^\n*/', '', $match); + + while (TRUE) { + if (preg_match('/^[ ]{'.$this->depth[$listlevel].'}/', substr($text, $real_position)) > 0) { + $real_position += $this->depth[$listlevel]; + $logical_position += $this->depth[$listlevel]; + $listlevel += 1; + continue; + } + if (preg_match('/^\t/', substr($text, $real_position)) > 0) { + $real_position += 1; + $logical_position += 4; + $listlevel += 1; + continue; + } + if (preg_match('/^[ ]{0,3}\d+\.[ \t]/', substr($text, $real_position)) > 0) { + $this->depth[$listlevel] = strlen(substr($text, $real_position)) - 1; + } + break; + } + return $listlevel; + } +} +//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/platform/www/lib/plugins/markdowku/syntax/references.php b/platform/www/lib/plugins/markdowku/syntax/references.php new file mode 100644 index 0000000..fe50a09 --- /dev/null +++ b/platform/www/lib/plugins/markdowku/syntax/references.php @@ -0,0 +1,41 @@ +<?php +/* + * References for links or images, i.e. + * [id]: http://example.com + */ + +if(!defined('DOKU_INC')) die(); +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +require_once(DOKU_PLUGIN.'syntax.php'); + +class syntax_plugin_markdowku_references extends DokuWiki_Syntax_Plugin { + + function getType() { return 'substition'; } + function getPType() { return 'normal'; } + function getSort() { return 100; } + + function connectTo($mode) { + $this->Lexer->addSpecialPattern( + '\n[ ]{0,3}\[[^\n]+?\]:[ \t]*\n?[ \t]*<?\S+?>?[ \t]*\n?[ \t]*(?:(?<=\s)["(].+?[")][\t]*)?(?=\n)', + $mode, + 'plugin_markdowku_references'); + } + + function handle($match, $state, $pos, Doku_Handler $handler) { + return array($state, $match); + } + + function render($mode, Doku_Renderer $renderer, $data) { + if ($mode != 'metadata') + return false; + + preg_match( + '/\[(.+)\]:[ \t]*\n?[ \t]*<?(\S+)>?[ \t]*\n?[ \t]*(?:(?<=\s)["(](.+?)[")][\t]*)?/', + $data[1], + $matches); + $key = 'markdowku_references_'.preg_replace("/ /", ".", $matches[1]); + $renderer->meta[$key] = $matches[2]; + return true; + } +} +//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/platform/www/lib/plugins/markdowku/syntax/ulists.php b/platform/www/lib/plugins/markdowku/syntax/ulists.php new file mode 100644 index 0000000..79393c2 --- /dev/null +++ b/platform/www/lib/plugins/markdowku/syntax/ulists.php @@ -0,0 +1,99 @@ +<?php +/* + * Unorderd lists: + * * ... + * * ... + */ + +if(!defined('DOKU_INC')) die(); +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +require_once(DOKU_PLUGIN.'syntax.php'); + +use dokuwiki\Parsing\Handler\Lists; + +class syntax_plugin_markdowku_ulists extends DokuWiki_Syntax_Plugin { + function getType() { return 'container'; } + function getPType() { return 'block'; } + function getSort() { return 9; } + function getAllowedTypes() { + return array('formatting', 'substition', 'paragraphs', 'baseonly', 'container'); + } + + function connectTo($mode) { + /* The negative lookahead is for not conflicting with hrs. */ + $this->Lexer->addEntryPattern( + '\n\n[ ]{0,3}[*+-][ \t](?!(?:[ ]?[*+-][ ]?){2,}[ \t]*\n)', + $mode, + 'plugin_markdowku_ulists'); + + $this->Lexer->addPattern( + '\n[ \t]*[*+-][ \t](?!(?:[ ]?[*+-][ ]?){2,}[ \t]*\n)', + 'plugin_markdowku_ulists'); + } + + function postConnect() { + $this->Lexer->addExitPattern( + '(?:\Z|\n{1,}(?=\n\S)(?!\n[ \t]*[*+-][ \t]))', + 'plugin_markdowku_ulists'); + } + + function handle($match, $state, $pos, Doku_Handler $handler) { + switch ($state) { + case DOKU_LEXER_ENTER: + $ReWriter = new Doku_Handler_Markdown_Unordered_List($handler->getCallWriter()); + $handler->setCallWriter($ReWriter); + $handler->_addCall('list_open', array($match), $pos); + break; + case DOKU_LEXER_MATCHED: + $handler->_addCall('list_item', array($match), $pos); + break; + case DOKU_LEXER_UNMATCHED: + $handler->_addCall('cdata', array($match), $pos); + break; + case DOKU_LEXER_EXIT: + $handler->_addCall('list_close', array(), $pos); + $handler->getCallWriter()->process(); + $ReWriter = & $handler->getCallWriter(); + $handler->setCallWriter($ReWriter->getCallWriter()); + break; + } + return true; + } + + function render($mode, Doku_Renderer $renderer, $data) { + return true; + } +} + +class Doku_Handler_Markdown_Unordered_List extends Lists { + private $depth = array(0, 4); + + function interpretSyntax($match, &$type) { + $type="u"; + $listlevel = 1; + $real_position = 0; + $logical_position = 0; + $text = preg_replace('/^\n*/', '', $match); + + while (TRUE) { + if (preg_match('/^[ ]{'.$this->depth[$listlevel].'}/', substr($text, $real_position)) > 0) { + $real_position += $this->depth[$listlevel]; + $logical_position += $this->depth[$listlevel]; + $listlevel += 1; + continue; + } + if (preg_match('/^\t/', substr($text, $real_position)) > 0) { + $real_position += 1; + $logical_position += 4; + $listlevel += 1; + continue; + } + if (preg_match('/^[ ]{0,3}[*+-][ \t]/', substr($text, $real_position)) > 0) { + $this->depth[$listlevel] = strlen(substr($text, $real_position)) - 1; + } + break; + } + return $listlevel + 1; + } +} +//Setup VIM: ex: et ts=4 enc=utf-8 : |