summaryrefslogtreecommitdiff
path: root/platform/www/inc/Parsing/ParserMode
diff options
context:
space:
mode:
Diffstat (limited to 'platform/www/inc/Parsing/ParserMode')
-rw-r--r--platform/www/inc/Parsing/ParserMode/AbstractMode.php40
-rw-r--r--platform/www/inc/Parsing/ParserMode/Acronym.php68
-rw-r--r--platform/www/inc/Parsing/ParserMode/Base.php31
-rw-r--r--platform/www/inc/Parsing/ParserMode/Camelcaselink.php23
-rw-r--r--platform/www/inc/Parsing/ParserMode/Code.php25
-rw-r--r--platform/www/inc/Parsing/ParserMode/Emaillink.php20
-rw-r--r--platform/www/inc/Parsing/ParserMode/Entity.php50
-rw-r--r--platform/www/inc/Parsing/ParserMode/Eol.php25
-rw-r--r--platform/www/inc/Parsing/ParserMode/Externallink.php44
-rw-r--r--platform/www/inc/Parsing/ParserMode/File.php25
-rw-r--r--platform/www/inc/Parsing/ParserMode/Filelink.php39
-rw-r--r--platform/www/inc/Parsing/ParserMode/Footnote.php50
-rw-r--r--platform/www/inc/Parsing/ParserMode/Formatting.php115
-rw-r--r--platform/www/inc/Parsing/ParserMode/Header.php24
-rw-r--r--platform/www/inc/Parsing/ParserMode/Hr.php19
-rw-r--r--platform/www/inc/Parsing/ParserMode/Html.php27
-rw-r--r--platform/www/inc/Parsing/ParserMode/Internallink.php20
-rw-r--r--platform/www/inc/Parsing/ParserMode/Linebreak.php19
-rw-r--r--platform/www/inc/Parsing/ParserMode/Listblock.php44
-rw-r--r--platform/www/inc/Parsing/ParserMode/Media.php20
-rw-r--r--platform/www/inc/Parsing/ParserMode/ModeInterface.php46
-rw-r--r--platform/www/inc/Parsing/ParserMode/Multiplyentity.php27
-rw-r--r--platform/www/inc/Parsing/ParserMode/Nocache.php19
-rw-r--r--platform/www/inc/Parsing/ParserMode/Notoc.php19
-rw-r--r--platform/www/inc/Parsing/ParserMode/Php.php27
-rw-r--r--platform/www/inc/Parsing/ParserMode/Plugin.php8
-rw-r--r--platform/www/inc/Parsing/ParserMode/Preformatted.php31
-rw-r--r--platform/www/inc/Parsing/ParserMode/Quote.php41
-rw-r--r--platform/www/inc/Parsing/ParserMode/Quotes.php51
-rw-r--r--platform/www/inc/Parsing/ParserMode/Rss.php19
-rw-r--r--platform/www/inc/Parsing/ParserMode/Smiley.php48
-rw-r--r--platform/www/inc/Parsing/ParserMode/Table.php47
-rw-r--r--platform/www/inc/Parsing/ParserMode/Unformatted.php28
-rw-r--r--platform/www/inc/Parsing/ParserMode/Windowssharelink.php31
-rw-r--r--platform/www/inc/Parsing/ParserMode/Wordblock.php52
35 files changed, 1222 insertions, 0 deletions
diff --git a/platform/www/inc/Parsing/ParserMode/AbstractMode.php b/platform/www/inc/Parsing/ParserMode/AbstractMode.php
new file mode 100644
index 0000000..15fc9fe
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/AbstractMode.php
@@ -0,0 +1,40 @@
+<?php
+
+namespace dokuwiki\Parsing\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 \dokuwiki\Parsing\Lexer\Lexer $Lexer will be injected on loading FIXME this should be done by setter */
+ 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/platform/www/inc/Parsing/ParserMode/Acronym.php b/platform/www/inc/Parsing/ParserMode/Acronym.php
new file mode 100644
index 0000000..b42a7b5
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Acronym.php
@@ -0,0 +1,68 @@
+<?php
+
+namespace dokuwiki\Parsing\ParserMode;
+
+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(['\\dokuwiki\\Parsing\\Lexer\\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/platform/www/inc/Parsing/ParserMode/Base.php b/platform/www/inc/Parsing/ParserMode/Base.php
new file mode 100644
index 0000000..5622756
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Base.php
@@ -0,0 +1,31 @@
+<?php
+
+namespace dokuwiki\Parsing\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/platform/www/inc/Parsing/ParserMode/Camelcaselink.php b/platform/www/inc/Parsing/ParserMode/Camelcaselink.php
new file mode 100644
index 0000000..ef0b325
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Camelcaselink.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace dokuwiki\Parsing\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/platform/www/inc/Parsing/ParserMode/Code.php b/platform/www/inc/Parsing/ParserMode/Code.php
new file mode 100644
index 0000000..aa49437
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Code.php
@@ -0,0 +1,25 @@
+<?php
+
+namespace dokuwiki\Parsing\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/platform/www/inc/Parsing/ParserMode/Emaillink.php b/platform/www/inc/Parsing/ParserMode/Emaillink.php
new file mode 100644
index 0000000..f9af28c
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Emaillink.php
@@ -0,0 +1,20 @@
+<?php
+
+namespace dokuwiki\Parsing\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/platform/www/inc/Parsing/ParserMode/Entity.php b/platform/www/inc/Parsing/ParserMode/Entity.php
new file mode 100644
index 0000000..b670124
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Entity.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace dokuwiki\Parsing\ParserMode;
+
+use dokuwiki\Parsing\Lexer\Lexer;
+
+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. 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/platform/www/inc/Parsing/ParserMode/Eol.php b/platform/www/inc/Parsing/ParserMode/Eol.php
new file mode 100644
index 0000000..a5886b5
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Eol.php
@@ -0,0 +1,25 @@
+<?php
+
+namespace dokuwiki\Parsing\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/platform/www/inc/Parsing/ParserMode/Externallink.php b/platform/www/inc/Parsing/ParserMode/Externallink.php
new file mode 100644
index 0000000..7475745
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Externallink.php
@@ -0,0 +1,44 @@
+<?php
+
+namespace dokuwiki\Parsing\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/platform/www/inc/Parsing/ParserMode/File.php b/platform/www/inc/Parsing/ParserMode/File.php
new file mode 100644
index 0000000..1491341
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/File.php
@@ -0,0 +1,25 @@
+<?php
+
+namespace dokuwiki\Parsing\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/platform/www/inc/Parsing/ParserMode/Filelink.php b/platform/www/inc/Parsing/ParserMode/Filelink.php
new file mode 100644
index 0000000..3cd86cb
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Filelink.php
@@ -0,0 +1,39 @@
+<?php
+
+namespace dokuwiki\Parsing\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/platform/www/inc/Parsing/ParserMode/Footnote.php b/platform/www/inc/Parsing/ParserMode/Footnote.php
new file mode 100644
index 0000000..c399f98
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Footnote.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace dokuwiki\Parsing\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/platform/www/inc/Parsing/ParserMode/Formatting.php b/platform/www/inc/Parsing/ParserMode/Formatting.php
new file mode 100644
index 0000000..a3c465c
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Formatting.php
@@ -0,0 +1,115 @@
+<?php
+
+namespace dokuwiki\Parsing\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/platform/www/inc/Parsing/ParserMode/Header.php b/platform/www/inc/Parsing/ParserMode/Header.php
new file mode 100644
index 0000000..854b317
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Header.php
@@ -0,0 +1,24 @@
+<?php
+
+namespace dokuwiki\Parsing\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/platform/www/inc/Parsing/ParserMode/Hr.php b/platform/www/inc/Parsing/ParserMode/Hr.php
new file mode 100644
index 0000000..e4f0b44
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Hr.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace dokuwiki\Parsing\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/platform/www/inc/Parsing/ParserMode/Html.php b/platform/www/inc/Parsing/ParserMode/Html.php
new file mode 100644
index 0000000..f5b63ef
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Html.php
@@ -0,0 +1,27 @@
+<?php
+
+namespace dokuwiki\Parsing\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/platform/www/inc/Parsing/ParserMode/Internallink.php b/platform/www/inc/Parsing/ParserMode/Internallink.php
new file mode 100644
index 0000000..6def0d9
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Internallink.php
@@ -0,0 +1,20 @@
+<?php
+
+namespace dokuwiki\Parsing\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/platform/www/inc/Parsing/ParserMode/Linebreak.php b/platform/www/inc/Parsing/ParserMode/Linebreak.php
new file mode 100644
index 0000000..dd95cc3
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Linebreak.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace dokuwiki\Parsing\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/platform/www/inc/Parsing/ParserMode/Listblock.php b/platform/www/inc/Parsing/ParserMode/Listblock.php
new file mode 100644
index 0000000..eef7627
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Listblock.php
@@ -0,0 +1,44 @@
+<?php
+
+namespace dokuwiki\Parsing\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/platform/www/inc/Parsing/ParserMode/Media.php b/platform/www/inc/Parsing/ParserMode/Media.php
new file mode 100644
index 0000000..f93f947
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Media.php
@@ -0,0 +1,20 @@
+<?php
+
+namespace dokuwiki\Parsing\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/platform/www/inc/Parsing/ParserMode/ModeInterface.php b/platform/www/inc/Parsing/ParserMode/ModeInterface.php
new file mode 100644
index 0000000..7cca038
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/ModeInterface.php
@@ -0,0 +1,46 @@
+<?php
+
+namespace dokuwiki\Parsing\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/platform/www/inc/Parsing/ParserMode/Multiplyentity.php b/platform/www/inc/Parsing/ParserMode/Multiplyentity.php
new file mode 100644
index 0000000..89df136
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Multiplyentity.php
@@ -0,0 +1,27 @@
+<?php
+
+namespace dokuwiki\Parsing\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/platform/www/inc/Parsing/ParserMode/Nocache.php b/platform/www/inc/Parsing/ParserMode/Nocache.php
new file mode 100644
index 0000000..fa6db83
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Nocache.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace dokuwiki\Parsing\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/platform/www/inc/Parsing/ParserMode/Notoc.php b/platform/www/inc/Parsing/ParserMode/Notoc.php
new file mode 100644
index 0000000..5956207
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Notoc.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace dokuwiki\Parsing\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/platform/www/inc/Parsing/ParserMode/Php.php b/platform/www/inc/Parsing/ParserMode/Php.php
new file mode 100644
index 0000000..914648b
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Php.php
@@ -0,0 +1,27 @@
+<?php
+
+namespace dokuwiki\Parsing\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/platform/www/inc/Parsing/ParserMode/Plugin.php b/platform/www/inc/Parsing/ParserMode/Plugin.php
new file mode 100644
index 0000000..c885c60
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Plugin.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace dokuwiki\Parsing\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/platform/www/inc/Parsing/ParserMode/Preformatted.php b/platform/www/inc/Parsing/ParserMode/Preformatted.php
new file mode 100644
index 0000000..7dfc474
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Preformatted.php
@@ -0,0 +1,31 @@
+<?php
+
+namespace dokuwiki\Parsing\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/platform/www/inc/Parsing/ParserMode/Quote.php b/platform/www/inc/Parsing/ParserMode/Quote.php
new file mode 100644
index 0000000..65525b2
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Quote.php
@@ -0,0 +1,41 @@
+<?php
+
+namespace dokuwiki\Parsing\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/platform/www/inc/Parsing/ParserMode/Quotes.php b/platform/www/inc/Parsing/ParserMode/Quotes.php
new file mode 100644
index 0000000..13db2e6
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Quotes.php
@@ -0,0 +1,51 @@
+<?php
+
+namespace dokuwiki\Parsing\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/platform/www/inc/Parsing/ParserMode/Rss.php b/platform/www/inc/Parsing/ParserMode/Rss.php
new file mode 100644
index 0000000..a62d9b8
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Rss.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace dokuwiki\Parsing\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/platform/www/inc/Parsing/ParserMode/Smiley.php b/platform/www/inc/Parsing/ParserMode/Smiley.php
new file mode 100644
index 0000000..084ccc9
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Smiley.php
@@ -0,0 +1,48 @@
+<?php
+
+namespace dokuwiki\Parsing\ParserMode;
+
+use dokuwiki\Parsing\Lexer\Lexer;
+
+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|^)'. 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/platform/www/inc/Parsing/ParserMode/Table.php b/platform/www/inc/Parsing/ParserMode/Table.php
new file mode 100644
index 0000000..b4b5123
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Table.php
@@ -0,0 +1,47 @@
+<?php
+
+namespace dokuwiki\Parsing\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/platform/www/inc/Parsing/ParserMode/Unformatted.php b/platform/www/inc/Parsing/ParserMode/Unformatted.php
new file mode 100644
index 0000000..1bc2826
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Unformatted.php
@@ -0,0 +1,28 @@
+<?php
+
+namespace dokuwiki\Parsing\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/platform/www/inc/Parsing/ParserMode/Windowssharelink.php b/platform/www/inc/Parsing/ParserMode/Windowssharelink.php
new file mode 100644
index 0000000..747d4d8
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Windowssharelink.php
@@ -0,0 +1,31 @@
+<?php
+
+namespace dokuwiki\Parsing\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/platform/www/inc/Parsing/ParserMode/Wordblock.php b/platform/www/inc/Parsing/ParserMode/Wordblock.php
new file mode 100644
index 0000000..50b24b2
--- /dev/null
+++ b/platform/www/inc/Parsing/ParserMode/Wordblock.php
@@ -0,0 +1,52 @@
+<?php
+
+namespace dokuwiki\Parsing\ParserMode;
+
+use dokuwiki\Parsing\Lexer\Lexer;
+
+/**
+ * @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)'. 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;
+ }
+}