diff options
Diffstat (limited to 'inc/ParserMode')
35 files changed, 1218 insertions, 0 deletions
diff --git a/inc/ParserMode/AbstractMode.php b/inc/ParserMode/AbstractMode.php new file mode 100644 index 000000000..ffd85e67a --- /dev/null +++ b/inc/ParserMode/AbstractMode.php @@ -0,0 +1,40 @@ +<?php + +namespace dokuwiki\ParserMode; + +/** + * This class and all the subclasses below are used to reduce the effort required to register + * modes with the Lexer. + * + * @author Harry Fuecks <hfuecks@gmail.com> + */ +abstract class AbstractMode implements ModeInterface +{ + /** @var \Doku_Lexer $Lexer will be injected on loading */ + public $Lexer; + protected $allowedModes = array(); + + /** @inheritdoc */ + abstract public function getSort(); + + /** @inheritdoc */ + public function preConnect() + { + } + + /** @inheritdoc */ + public function connectTo($mode) + { + } + + /** @inheritdoc */ + public function postConnect() + { + } + + /** @inheritdoc */ + public function accepts($mode) + { + return in_array($mode, (array) $this->allowedModes); + } +} diff --git a/inc/ParserMode/Acronym.php b/inc/ParserMode/Acronym.php new file mode 100644 index 000000000..f53c818b4 --- /dev/null +++ b/inc/ParserMode/Acronym.php @@ -0,0 +1,70 @@ +<?php + +namespace dokuwiki\ParserMode; + +use dokuwiki\Action\AbstractAclAction; + +class Acronym extends AbstractMode +{ + // A list + protected $acronyms = array(); + protected $pattern = ''; + + /** + * Acronym constructor. + * + * @param string[] $acronyms + */ + public function __construct($acronyms) + { + usort($acronyms, array($this,'compare')); + $this->acronyms = $acronyms; + } + + /** @inheritdoc */ + public function preConnect() + { + if (!count($this->acronyms)) return; + + $bound = '[\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]'; + $acronyms = array_map('Doku_Lexer_Escape', $this->acronyms); + $this->pattern = '(?<=^|'.$bound.')(?:'.join('|', $acronyms).')(?='.$bound.')'; + } + + /** @inheritdoc */ + public function connectTo($mode) + { + if (!count($this->acronyms)) return; + + if (strlen($this->pattern) > 0) { + $this->Lexer->addSpecialPattern($this->pattern, $mode, 'acronym'); + } + } + + /** @inheritdoc */ + public function getSort() + { + return 240; + } + + /** + * sort callback to order by string length descending + * + * @param string $a + * @param string $b + * + * @return int + */ + protected function compare($a, $b) + { + $a_len = strlen($a); + $b_len = strlen($b); + if ($a_len > $b_len) { + return -1; + } elseif ($a_len < $b_len) { + return 1; + } + + return 0; + } +} diff --git a/inc/ParserMode/Base.php b/inc/ParserMode/Base.php new file mode 100644 index 000000000..e399bbfd4 --- /dev/null +++ b/inc/ParserMode/Base.php @@ -0,0 +1,31 @@ +<?php + +namespace dokuwiki\ParserMode; + +class Base extends AbstractMode +{ + + /** + * Base constructor. + */ + public function __construct() + { + global $PARSER_MODES; + + $this->allowedModes = array_merge( + $PARSER_MODES['container'], + $PARSER_MODES['baseonly'], + $PARSER_MODES['paragraphs'], + $PARSER_MODES['formatting'], + $PARSER_MODES['substition'], + $PARSER_MODES['protected'], + $PARSER_MODES['disabled'] + ); + } + + /** @inheritdoc */ + public function getSort() + { + return 0; + } +} diff --git a/inc/ParserMode/Camelcaselink.php b/inc/ParserMode/Camelcaselink.php new file mode 100644 index 000000000..e6461f368 --- /dev/null +++ b/inc/ParserMode/Camelcaselink.php @@ -0,0 +1,23 @@ +<?php + +namespace dokuwiki\ParserMode; + +class Camelcaselink extends AbstractMode +{ + + /** @inheritdoc */ + public function connectTo($mode) + { + $this->Lexer->addSpecialPattern( + '\b[A-Z]+[a-z]+[A-Z][A-Za-z]*\b', + $mode, + 'camelcaselink' + ); + } + + /** @inheritdoc */ + public function getSort() + { + return 290; + } +} diff --git a/inc/ParserMode/Code.php b/inc/ParserMode/Code.php new file mode 100644 index 000000000..9ee956d6e --- /dev/null +++ b/inc/ParserMode/Code.php @@ -0,0 +1,25 @@ +<?php + +namespace dokuwiki\ParserMode; + +class Code extends AbstractMode +{ + + /** @inheritdoc */ + public function connectTo($mode) + { + $this->Lexer->addEntryPattern('<code\b(?=.*</code>)', $mode, 'code'); + } + + /** @inheritdoc */ + public function postConnect() + { + $this->Lexer->addExitPattern('</code>', 'code'); + } + + /** @inheritdoc */ + public function getSort() + { + return 200; + } +} diff --git a/inc/ParserMode/Emaillink.php b/inc/ParserMode/Emaillink.php new file mode 100644 index 000000000..1e047e698 --- /dev/null +++ b/inc/ParserMode/Emaillink.php @@ -0,0 +1,20 @@ +<?php + +namespace dokuwiki\ParserMode; + +class Emaillink extends AbstractMode +{ + + /** @inheritdoc */ + public function connectTo($mode) + { + // pattern below is defined in inc/mail.php + $this->Lexer->addSpecialPattern('<'.PREG_PATTERN_VALID_EMAIL.'>', $mode, 'emaillink'); + } + + /** @inheritdoc */ + public function getSort() + { + return 340; + } +} diff --git a/inc/ParserMode/Entity.php b/inc/ParserMode/Entity.php new file mode 100644 index 000000000..c551cbca9 --- /dev/null +++ b/inc/ParserMode/Entity.php @@ -0,0 +1,48 @@ +<?php + +namespace dokuwiki\ParserMode; + +class Entity extends AbstractMode +{ + + protected $entities = array(); + protected $pattern = ''; + + /** + * Entity constructor. + * @param string[] $entities + */ + public function __construct($entities) + { + $this->entities = $entities; + } + + + /** @inheritdoc */ + public function preConnect() + { + if (!count($this->entities) || $this->pattern != '') return; + + $sep = ''; + foreach ($this->entities as $entity) { + $this->pattern .= $sep.Doku_Lexer_Escape($entity); + $sep = '|'; + } + } + + /** @inheritdoc */ + public function connectTo($mode) + { + if (!count($this->entities)) return; + + if (strlen($this->pattern) > 0) { + $this->Lexer->addSpecialPattern($this->pattern, $mode, 'entity'); + } + } + + /** @inheritdoc */ + public function getSort() + { + return 260; + } +} diff --git a/inc/ParserMode/Eol.php b/inc/ParserMode/Eol.php new file mode 100644 index 000000000..f60672e50 --- /dev/null +++ b/inc/ParserMode/Eol.php @@ -0,0 +1,25 @@ +<?php + +namespace dokuwiki\ParserMode; + +class Eol extends AbstractMode +{ + + /** @inheritdoc */ + public function connectTo($mode) + { + $badModes = array('listblock','table'); + if (in_array($mode, $badModes)) { + return; + } + // see FS#1652, pattern extended to swallow preceding whitespace to avoid + // issues with lines that only contain whitespace + $this->Lexer->addSpecialPattern('(?:^[ \t]*)?\n', $mode, 'eol'); + } + + /** @inheritdoc */ + public function getSort() + { + return 370; + } +} diff --git a/inc/ParserMode/Externallink.php b/inc/ParserMode/Externallink.php new file mode 100644 index 000000000..f01a69f7d --- /dev/null +++ b/inc/ParserMode/Externallink.php @@ -0,0 +1,44 @@ +<?php + +namespace dokuwiki\ParserMode; + +class Externallink extends AbstractMode +{ + protected $schemes = array(); + protected $patterns = array(); + + /** @inheritdoc */ + public function preConnect() + { + if (count($this->patterns)) return; + + $ltrs = '\w'; + $gunk = '/\#~:.?+=&%@!\-\[\]'; + $punc = '.:?\-;,'; + $host = $ltrs.$punc; + $any = $ltrs.$gunk.$punc; + + $this->schemes = getSchemes(); + foreach ($this->schemes as $scheme) { + $this->patterns[] = '\b(?i)'.$scheme.'(?-i)://['.$any.']+?(?=['.$punc.']*[^'.$any.'])'; + } + + $this->patterns[] = '(?<=\s)(?i)www?(?-i)\.['.$host.']+?\.['.$host.']+?['.$any.']+?(?=['.$punc.']*[^'.$any.'])'; + $this->patterns[] = '(?<=\s)(?i)ftp?(?-i)\.['.$host.']+?\.['.$host.']+?['.$any.']+?(?=['.$punc.']*[^'.$any.'])'; + } + + /** @inheritdoc */ + public function connectTo($mode) + { + + foreach ($this->patterns as $pattern) { + $this->Lexer->addSpecialPattern($pattern, $mode, 'externallink'); + } + } + + /** @inheritdoc */ + public function getSort() + { + return 330; + } +} diff --git a/inc/ParserMode/File.php b/inc/ParserMode/File.php new file mode 100644 index 000000000..7f9e07162 --- /dev/null +++ b/inc/ParserMode/File.php @@ -0,0 +1,25 @@ +<?php + +namespace dokuwiki\ParserMode; + +class File extends AbstractMode +{ + + /** @inheritdoc */ + public function connectTo($mode) + { + $this->Lexer->addEntryPattern('<file\b(?=.*</file>)', $mode, 'file'); + } + + /** @inheritdoc */ + public function postConnect() + { + $this->Lexer->addExitPattern('</file>', 'file'); + } + + /** @inheritdoc */ + public function getSort() + { + return 210; + } +} diff --git a/inc/ParserMode/Filelink.php b/inc/ParserMode/Filelink.php new file mode 100644 index 000000000..f48ea10c5 --- /dev/null +++ b/inc/ParserMode/Filelink.php @@ -0,0 +1,39 @@ +<?php + +namespace dokuwiki\ParserMode; + +class Filelink extends AbstractMode +{ + + protected $pattern; + + /** @inheritdoc */ + public function preConnect() + { + + $ltrs = '\w'; + $gunk = '/\#~:.?+=&%@!\-'; + $punc = '.:?\-;,'; + $host = $ltrs.$punc; + $any = $ltrs.$gunk.$punc; + + $this->pattern = '\b(?i)file(?-i)://['.$any.']+?['. + $punc.']*[^'.$any.']'; + } + + /** @inheritdoc */ + public function connectTo($mode) + { + $this->Lexer->addSpecialPattern( + $this->pattern, + $mode, + 'filelink' + ); + } + + /** @inheritdoc */ + public function getSort() + { + return 360; + } +} diff --git a/inc/ParserMode/Footnote.php b/inc/ParserMode/Footnote.php new file mode 100644 index 000000000..73813e290 --- /dev/null +++ b/inc/ParserMode/Footnote.php @@ -0,0 +1,50 @@ +<?php + +namespace dokuwiki\ParserMode; + +class Footnote extends AbstractMode +{ + + /** + * Footnote constructor. + */ + public function __construct() + { + global $PARSER_MODES; + + $this->allowedModes = array_merge( + $PARSER_MODES['container'], + $PARSER_MODES['formatting'], + $PARSER_MODES['substition'], + $PARSER_MODES['protected'], + $PARSER_MODES['disabled'] + ); + + unset($this->allowedModes[array_search('footnote', $this->allowedModes)]); + } + + /** @inheritdoc */ + public function connectTo($mode) + { + $this->Lexer->addEntryPattern( + '\x28\x28(?=.*\x29\x29)', + $mode, + 'footnote' + ); + } + + /** @inheritdoc */ + public function postConnect() + { + $this->Lexer->addExitPattern( + '\x29\x29', + 'footnote' + ); + } + + /** @inheritdoc */ + public function getSort() + { + return 150; + } +} diff --git a/inc/ParserMode/Formatting.php b/inc/ParserMode/Formatting.php new file mode 100644 index 000000000..caa48c94b --- /dev/null +++ b/inc/ParserMode/Formatting.php @@ -0,0 +1,115 @@ +<?php + +namespace dokuwiki\ParserMode; + +/** + * This class sets the markup for bold (=strong), + * italic (=emphasis), underline etc. + */ +class Formatting extends AbstractMode +{ + protected $type; + + protected $formatting = array( + 'strong' => array( + 'entry' => '\*\*(?=.*\*\*)', + 'exit' => '\*\*', + 'sort' => 70 + ), + + 'emphasis' => array( + 'entry' => '//(?=[^\x00]*[^:])', //hack for bugs #384 #763 #1468 + 'exit' => '//', + 'sort' => 80 + ), + + 'underline' => array( + 'entry' => '__(?=.*__)', + 'exit' => '__', + 'sort' => 90 + ), + + 'monospace' => array( + 'entry' => '\x27\x27(?=.*\x27\x27)', + 'exit' => '\x27\x27', + 'sort' => 100 + ), + + 'subscript' => array( + 'entry' => '<sub>(?=.*</sub>)', + 'exit' => '</sub>', + 'sort' => 110 + ), + + 'superscript' => array( + 'entry' => '<sup>(?=.*</sup>)', + 'exit' => '</sup>', + 'sort' => 120 + ), + + 'deleted' => array( + 'entry' => '<del>(?=.*</del>)', + 'exit' => '</del>', + 'sort' => 130 + ), + ); + + /** + * @param string $type + */ + public function __construct($type) + { + global $PARSER_MODES; + + if (!array_key_exists($type, $this->formatting)) { + trigger_error('Invalid formatting type ' . $type, E_USER_WARNING); + } + + $this->type = $type; + + // formatting may contain other formatting but not it self + $modes = $PARSER_MODES['formatting']; + $key = array_search($type, $modes); + if (is_int($key)) { + unset($modes[$key]); + } + + $this->allowedModes = array_merge( + $modes, + $PARSER_MODES['substition'], + $PARSER_MODES['disabled'] + ); + } + + /** @inheritdoc */ + public function connectTo($mode) + { + + // Can't nest formatting in itself + if ($mode == $this->type) { + return; + } + + $this->Lexer->addEntryPattern( + $this->formatting[$this->type]['entry'], + $mode, + $this->type + ); + } + + /** @inheritdoc */ + public function postConnect() + { + + $this->Lexer->addExitPattern( + $this->formatting[$this->type]['exit'], + $this->type + ); + } + + /** @inheritdoc */ + public function getSort() + { + return $this->formatting[$this->type]['sort']; + } +} diff --git a/inc/ParserMode/Header.php b/inc/ParserMode/Header.php new file mode 100644 index 000000000..2da3242cf --- /dev/null +++ b/inc/ParserMode/Header.php @@ -0,0 +1,24 @@ +<?php + +namespace dokuwiki\ParserMode; + +class Header extends AbstractMode +{ + + /** @inheritdoc */ + public function connectTo($mode) + { + //we're not picky about the closing ones, two are enough + $this->Lexer->addSpecialPattern( + '[ \t]*={2,}[^\n]+={2,}[ \t]*(?=\n)', + $mode, + 'header' + ); + } + + /** @inheritdoc */ + public function getSort() + { + return 50; + } +} diff --git a/inc/ParserMode/Hr.php b/inc/ParserMode/Hr.php new file mode 100644 index 000000000..3c36f31c4 --- /dev/null +++ b/inc/ParserMode/Hr.php @@ -0,0 +1,19 @@ +<?php + +namespace dokuwiki\ParserMode; + +class Hr extends AbstractMode +{ + + /** @inheritdoc */ + public function connectTo($mode) + { + $this->Lexer->addSpecialPattern('\n[ \t]*-{4,}[ \t]*(?=\n)', $mode, 'hr'); + } + + /** @inheritdoc */ + public function getSort() + { + return 160; + } +} diff --git a/inc/ParserMode/Html.php b/inc/ParserMode/Html.php new file mode 100644 index 000000000..2ad7cfb7c --- /dev/null +++ b/inc/ParserMode/Html.php @@ -0,0 +1,27 @@ +<?php + +namespace dokuwiki\ParserMode; + +class Html extends AbstractMode +{ + + /** @inheritdoc */ + public function connectTo($mode) + { + $this->Lexer->addEntryPattern('<html>(?=.*</html>)', $mode, 'html'); + $this->Lexer->addEntryPattern('<HTML>(?=.*</HTML>)', $mode, 'htmlblock'); + } + + /** @inheritdoc */ + public function postConnect() + { + $this->Lexer->addExitPattern('</html>', 'html'); + $this->Lexer->addExitPattern('</HTML>', 'htmlblock'); + } + + /** @inheritdoc */ + public function getSort() + { + return 190; + } +} diff --git a/inc/ParserMode/Internallink.php b/inc/ParserMode/Internallink.php new file mode 100644 index 000000000..d0b1dc0f4 --- /dev/null +++ b/inc/ParserMode/Internallink.php @@ -0,0 +1,20 @@ +<?php + +namespace dokuwiki\ParserMode; + +class Internallink extends AbstractMode +{ + + /** @inheritdoc */ + public function connectTo($mode) + { + // Word boundaries? + $this->Lexer->addSpecialPattern("\[\[.*?\]\](?!\])", $mode, 'internallink'); + } + + /** @inheritdoc */ + public function getSort() + { + return 300; + } +} diff --git a/inc/ParserMode/Linebreak.php b/inc/ParserMode/Linebreak.php new file mode 100644 index 000000000..4c1e51bf3 --- /dev/null +++ b/inc/ParserMode/Linebreak.php @@ -0,0 +1,19 @@ +<?php + +namespace dokuwiki\ParserMode; + +class Linebreak extends AbstractMode +{ + + /** @inheritdoc */ + public function connectTo($mode) + { + $this->Lexer->addSpecialPattern('\x5C{2}(?:[ \t]|(?=\n))', $mode, 'linebreak'); + } + + /** @inheritdoc */ + public function getSort() + { + return 140; + } +} diff --git a/inc/ParserMode/Listblock.php b/inc/ParserMode/Listblock.php new file mode 100644 index 000000000..32853862e --- /dev/null +++ b/inc/ParserMode/Listblock.php @@ -0,0 +1,44 @@ +<?php + +namespace dokuwiki\ParserMode; + +class Listblock extends AbstractMode +{ + + /** + * Listblock constructor. + */ + public function __construct() + { + global $PARSER_MODES; + + $this->allowedModes = array_merge( + $PARSER_MODES['formatting'], + $PARSER_MODES['substition'], + $PARSER_MODES['disabled'], + $PARSER_MODES['protected'] + ); + } + + /** @inheritdoc */ + public function connectTo($mode) + { + $this->Lexer->addEntryPattern('[ \t]*\n {2,}[\-\*]', $mode, 'listblock'); + $this->Lexer->addEntryPattern('[ \t]*\n\t{1,}[\-\*]', $mode, 'listblock'); + + $this->Lexer->addPattern('\n {2,}[\-\*]', 'listblock'); + $this->Lexer->addPattern('\n\t{1,}[\-\*]', 'listblock'); + } + + /** @inheritdoc */ + public function postConnect() + { + $this->Lexer->addExitPattern('\n', 'listblock'); + } + + /** @inheritdoc */ + public function getSort() + { + return 10; + } +} diff --git a/inc/ParserMode/Media.php b/inc/ParserMode/Media.php new file mode 100644 index 000000000..08e6f6852 --- /dev/null +++ b/inc/ParserMode/Media.php @@ -0,0 +1,20 @@ +<?php + +namespace dokuwiki\ParserMode; + +class Media extends AbstractMode +{ + + /** @inheritdoc */ + public function connectTo($mode) + { + // Word boundaries? + $this->Lexer->addSpecialPattern("\{\{(?:[^\}]|(?:\}[^\}]))+\}\}", $mode, 'media'); + } + + /** @inheritdoc */ + public function getSort() + { + return 320; + } +} diff --git a/inc/ParserMode/ModeInterface.php b/inc/ParserMode/ModeInterface.php new file mode 100644 index 000000000..ac599687d --- /dev/null +++ b/inc/ParserMode/ModeInterface.php @@ -0,0 +1,46 @@ +<?php + +namespace dokuwiki\ParserMode; + +/** + * Defines a mode (syntax component) in the Parser + */ +interface ModeInterface +{ + /** + * returns a number used to determine in which order modes are added + * + * @return int; + */ + public function getSort(); + + /** + * Called before any calls to connectTo + * + * @return void + */ + public function preConnect(); + + /** + * Connects the mode + * + * @param string $mode + * @return void + */ + public function connectTo($mode); + + /** + * Called after all calls to connectTo + * + * @return void + */ + public function postConnect(); + + /** + * Check if given mode is accepted inside this mode + * + * @param string $mode + * @return bool + */ + public function accepts($mode); +} diff --git a/inc/ParserMode/Multiplyentity.php b/inc/ParserMode/Multiplyentity.php new file mode 100644 index 000000000..9e5e377c7 --- /dev/null +++ b/inc/ParserMode/Multiplyentity.php @@ -0,0 +1,27 @@ +<?php + +namespace dokuwiki\ParserMode; + +/** + * Implements the 640x480 replacement + */ +class Multiplyentity extends AbstractMode +{ + + /** @inheritdoc */ + public function connectTo($mode) + { + + $this->Lexer->addSpecialPattern( + '(?<=\b)(?:[1-9]|\d{2,})[xX]\d+(?=\b)', + $mode, + 'multiplyentity' + ); + } + + /** @inheritdoc */ + public function getSort() + { + return 270; + } +} diff --git a/inc/ParserMode/Nocache.php b/inc/ParserMode/Nocache.php new file mode 100644 index 000000000..44728652e --- /dev/null +++ b/inc/ParserMode/Nocache.php @@ -0,0 +1,19 @@ +<?php + +namespace dokuwiki\ParserMode; + +class Nocache extends AbstractMode +{ + + /** @inheritdoc */ + public function connectTo($mode) + { + $this->Lexer->addSpecialPattern('~~NOCACHE~~', $mode, 'nocache'); + } + + /** @inheritdoc */ + public function getSort() + { + return 40; + } +} diff --git a/inc/ParserMode/Notoc.php b/inc/ParserMode/Notoc.php new file mode 100644 index 000000000..2af1b2080 --- /dev/null +++ b/inc/ParserMode/Notoc.php @@ -0,0 +1,19 @@ +<?php + +namespace dokuwiki\ParserMode; + +class Notoc extends AbstractMode +{ + + /** @inheritdoc */ + public function connectTo($mode) + { + $this->Lexer->addSpecialPattern('~~NOTOC~~', $mode, 'notoc'); + } + + /** @inheritdoc */ + public function getSort() + { + return 30; + } +} diff --git a/inc/ParserMode/Php.php b/inc/ParserMode/Php.php new file mode 100644 index 000000000..196569194 --- /dev/null +++ b/inc/ParserMode/Php.php @@ -0,0 +1,27 @@ +<?php + +namespace dokuwiki\ParserMode; + +class Php extends AbstractMode +{ + + /** @inheritdoc */ + public function connectTo($mode) + { + $this->Lexer->addEntryPattern('<php>(?=.*</php>)', $mode, 'php'); + $this->Lexer->addEntryPattern('<PHP>(?=.*</PHP>)', $mode, 'phpblock'); + } + + /** @inheritdoc */ + public function postConnect() + { + $this->Lexer->addExitPattern('</php>', 'php'); + $this->Lexer->addExitPattern('</PHP>', 'phpblock'); + } + + /** @inheritdoc */ + public function getSort() + { + return 180; + } +} diff --git a/inc/ParserMode/Plugin.php b/inc/ParserMode/Plugin.php new file mode 100644 index 000000000..186c7231a --- /dev/null +++ b/inc/ParserMode/Plugin.php @@ -0,0 +1,8 @@ +<?php + +namespace dokuwiki\ParserMode; + +/** + * @fixme do we need this anymore or could the syntax plugin inherit directly from abstract mode? + */ +abstract class Plugin extends AbstractMode {} diff --git a/inc/ParserMode/Preformatted.php b/inc/ParserMode/Preformatted.php new file mode 100644 index 000000000..2a25d223d --- /dev/null +++ b/inc/ParserMode/Preformatted.php @@ -0,0 +1,31 @@ +<?php + +namespace dokuwiki\ParserMode; + +class Preformatted extends AbstractMode +{ + + /** @inheritdoc */ + public function connectTo($mode) + { + // Has hard coded awareness of lists... + $this->Lexer->addEntryPattern('\n (?![\*\-])', $mode, 'preformatted'); + $this->Lexer->addEntryPattern('\n\t(?![\*\-])', $mode, 'preformatted'); + + // How to effect a sub pattern with the Lexer! + $this->Lexer->addPattern('\n ', 'preformatted'); + $this->Lexer->addPattern('\n\t', 'preformatted'); + } + + /** @inheritdoc */ + public function postConnect() + { + $this->Lexer->addExitPattern('\n', 'preformatted'); + } + + /** @inheritdoc */ + public function getSort() + { + return 20; + } +} diff --git a/inc/ParserMode/Quote.php b/inc/ParserMode/Quote.php new file mode 100644 index 000000000..5fe757ea1 --- /dev/null +++ b/inc/ParserMode/Quote.php @@ -0,0 +1,41 @@ +<?php + +namespace dokuwiki\ParserMode; + +class Quote extends AbstractMode +{ + + /** + * Quote constructor. + */ + public function __construct() + { + global $PARSER_MODES; + + $this->allowedModes = array_merge( + $PARSER_MODES['formatting'], + $PARSER_MODES['substition'], + $PARSER_MODES['disabled'], + $PARSER_MODES['protected'] + ); + } + + /** @inheritdoc */ + public function connectTo($mode) + { + $this->Lexer->addEntryPattern('\n>{1,}', $mode, 'quote'); + } + + /** @inheritdoc */ + public function postConnect() + { + $this->Lexer->addPattern('\n>{1,}', 'quote'); + $this->Lexer->addExitPattern('\n', 'quote'); + } + + /** @inheritdoc */ + public function getSort() + { + return 220; + } +} diff --git a/inc/ParserMode/Quotes.php b/inc/ParserMode/Quotes.php new file mode 100644 index 000000000..6086390cb --- /dev/null +++ b/inc/ParserMode/Quotes.php @@ -0,0 +1,51 @@ +<?php + +namespace dokuwiki\ParserMode; + +class Quotes extends AbstractMode +{ + + /** @inheritdoc */ + public function connectTo($mode) + { + global $conf; + + $ws = '\s/\#~:+=&%@\-\x28\x29\]\[{}><"\''; // whitespace + $punc = ';,\.?!'; + + if ($conf['typography'] == 2) { + $this->Lexer->addSpecialPattern( + "(?<=^|[$ws])'(?=[^$ws$punc])", + $mode, + 'singlequoteopening' + ); + $this->Lexer->addSpecialPattern( + "(?<=^|[^$ws]|[$punc])'(?=$|[$ws$punc])", + $mode, + 'singlequoteclosing' + ); + $this->Lexer->addSpecialPattern( + "(?<=^|[^$ws$punc])'(?=$|[^$ws$punc])", + $mode, + 'apostrophe' + ); + } + + $this->Lexer->addSpecialPattern( + "(?<=^|[$ws])\"(?=[^$ws$punc])", + $mode, + 'doublequoteopening' + ); + $this->Lexer->addSpecialPattern( + "\"", + $mode, + 'doublequoteclosing' + ); + } + + /** @inheritdoc */ + public function getSort() + { + return 280; + } +} diff --git a/inc/ParserMode/Rss.php b/inc/ParserMode/Rss.php new file mode 100644 index 000000000..197c9e2f4 --- /dev/null +++ b/inc/ParserMode/Rss.php @@ -0,0 +1,19 @@ +<?php + +namespace dokuwiki\ParserMode; + +class Rss extends AbstractMode +{ + + /** @inheritdoc */ + public function connectTo($mode) + { + $this->Lexer->addSpecialPattern("\{\{rss>[^\}]+\}\}", $mode, 'rss'); + } + + /** @inheritdoc */ + public function getSort() + { + return 310; + } +} diff --git a/inc/ParserMode/Smiley.php b/inc/ParserMode/Smiley.php new file mode 100644 index 000000000..73d302e2f --- /dev/null +++ b/inc/ParserMode/Smiley.php @@ -0,0 +1,46 @@ +<?php + +namespace dokuwiki\ParserMode; + +class Smiley extends AbstractMode +{ + protected $smileys = array(); + protected $pattern = ''; + + /** + * Smiley constructor. + * @param string[] $smileys + */ + public function __construct($smileys) + { + $this->smileys = $smileys; + } + + /** @inheritdoc */ + public function preConnect() + { + if (!count($this->smileys) || $this->pattern != '') return; + + $sep = ''; + foreach ($this->smileys as $smiley) { + $this->pattern .= $sep.'(?<=\W|^)'.Doku_Lexer_Escape($smiley).'(?=\W|$)'; + $sep = '|'; + } + } + + /** @inheritdoc */ + public function connectTo($mode) + { + if (!count($this->smileys)) return; + + if (strlen($this->pattern) > 0) { + $this->Lexer->addSpecialPattern($this->pattern, $mode, 'smiley'); + } + } + + /** @inheritdoc */ + public function getSort() + { + return 230; + } +} diff --git a/inc/ParserMode/Table.php b/inc/ParserMode/Table.php new file mode 100644 index 000000000..2d27aa992 --- /dev/null +++ b/inc/ParserMode/Table.php @@ -0,0 +1,47 @@ +<?php + +namespace dokuwiki\ParserMode; + +class Table extends AbstractMode +{ + + /** + * Table constructor. + */ + public function __construct() + { + global $PARSER_MODES; + + $this->allowedModes = array_merge( + $PARSER_MODES['formatting'], + $PARSER_MODES['substition'], + $PARSER_MODES['disabled'], + $PARSER_MODES['protected'] + ); + } + + /** @inheritdoc */ + public function connectTo($mode) + { + $this->Lexer->addEntryPattern('[\t ]*\n\^', $mode, 'table'); + $this->Lexer->addEntryPattern('[\t ]*\n\|', $mode, 'table'); + } + + /** @inheritdoc */ + public function postConnect() + { + $this->Lexer->addPattern('\n\^', 'table'); + $this->Lexer->addPattern('\n\|', 'table'); + $this->Lexer->addPattern('[\t ]*:::[\t ]*(?=[\|\^])', 'table'); + $this->Lexer->addPattern('[\t ]+', 'table'); + $this->Lexer->addPattern('\^', 'table'); + $this->Lexer->addPattern('\|', 'table'); + $this->Lexer->addExitPattern('\n', 'table'); + } + + /** @inheritdoc */ + public function getSort() + { + return 60; + } +} diff --git a/inc/ParserMode/Unformatted.php b/inc/ParserMode/Unformatted.php new file mode 100644 index 000000000..c85fb1354 --- /dev/null +++ b/inc/ParserMode/Unformatted.php @@ -0,0 +1,28 @@ +<?php + +namespace dokuwiki\ParserMode; + +class Unformatted extends AbstractMode +{ + + /** @inheritdoc */ + public function connectTo($mode) + { + $this->Lexer->addEntryPattern('<nowiki>(?=.*</nowiki>)', $mode, 'unformatted'); + $this->Lexer->addEntryPattern('%%(?=.*%%)', $mode, 'unformattedalt'); + } + + /** @inheritdoc */ + public function postConnect() + { + $this->Lexer->addExitPattern('</nowiki>', 'unformatted'); + $this->Lexer->addExitPattern('%%', 'unformattedalt'); + $this->Lexer->mapHandler('unformattedalt', 'unformatted'); + } + + /** @inheritdoc */ + public function getSort() + { + return 170; + } +} diff --git a/inc/ParserMode/Windowssharelink.php b/inc/ParserMode/Windowssharelink.php new file mode 100644 index 000000000..77e0a3dff --- /dev/null +++ b/inc/ParserMode/Windowssharelink.php @@ -0,0 +1,31 @@ +<?php + +namespace dokuwiki\ParserMode; + +class Windowssharelink extends AbstractMode +{ + + protected $pattern; + + /** @inheritdoc */ + public function preConnect() + { + $this->pattern = "\\\\\\\\\w+?(?:\\\\[\w\-$]+)+"; + } + + /** @inheritdoc */ + public function connectTo($mode) + { + $this->Lexer->addSpecialPattern( + $this->pattern, + $mode, + 'windowssharelink' + ); + } + + /** @inheritdoc */ + public function getSort() + { + return 350; + } +} diff --git a/inc/ParserMode/Wordblock.php b/inc/ParserMode/Wordblock.php new file mode 100644 index 000000000..3aa8ad208 --- /dev/null +++ b/inc/ParserMode/Wordblock.php @@ -0,0 +1,50 @@ +<?php + +namespace dokuwiki\ParserMode; + +/** + * @fixme is this actually used? + */ +class Wordblock extends AbstractMode +{ + protected $badwords = array(); + protected $pattern = ''; + + /** + * Wordblock constructor. + * @param $badwords + */ + public function __construct($badwords) + { + $this->badwords = $badwords; + } + + /** @inheritdoc */ + public function preConnect() + { + + if (count($this->badwords) == 0 || $this->pattern != '') { + return; + } + + $sep = ''; + foreach ($this->badwords as $badword) { + $this->pattern .= $sep.'(?<=\b)(?i)'.Doku_Lexer_Escape($badword).'(?-i)(?=\b)'; + $sep = '|'; + } + } + + /** @inheritdoc */ + public function connectTo($mode) + { + if (strlen($this->pattern) > 0) { + $this->Lexer->addSpecialPattern($this->pattern, $mode, 'wordblock'); + } + } + + /** @inheritdoc */ + public function getSort() + { + return 250; + } +} |