diff options
author | Andreas Gohr <andi@splitbrain.org> | 2018-04-28 12:12:06 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2018-04-28 12:12:06 +0200 |
commit | 36dc94bb8b05aaaff6fdcf55dd6af80ca30d22b1 (patch) | |
tree | c3f463108ed11ef8e05aab892ceaa16c1b50e6b8 | |
parent | de369923ccbbc3c1e79fd7b4d03677397e03876a (diff) | |
download | dokuwiki-36dc94bb8b05aaaff6fdcf55dd6af80ca30d22b1.tar.gz dokuwiki-36dc94bb8b05aaaff6fdcf55dd6af80ca30d22b1.zip |
split out parser modes into their own files
This moves all the parser classes into their own namespace and files.
Next up are the handler classes.
I'm not sure about the namespace, yet. A nested namepspace Parser\Modes
would probably make more sense... we'll see.
This also removes the duplicated coded in the Plugin mode. We now use
the plugin trait and can inherit from AbstractMode instead.
52 files changed, 1532 insertions, 1124 deletions
diff --git a/_test/tests/inc/parser/parser_code.test.php b/_test/tests/inc/parser/parser_code.test.php index df8225f4e..1c79462c3 100644 --- a/_test/tests/inc/parser/parser_code.test.php +++ b/_test/tests/inc/parser/parser_code.test.php @@ -1,4 +1,7 @@ <?php + +use dokuwiki\ParserMode\Code; + require_once 'parser.inc.php'; /** @@ -10,7 +13,7 @@ class TestOfDoku_Parser_Code extends TestOfDoku_Parser { function setUp() { parent::setUp(); - $this->P->addMode('code',new Doku_Parser_Mode_Code()); + $this->P->addMode('code',new Code()); } function testCode() { diff --git a/_test/tests/inc/parser/parser_eol.test.php b/_test/tests/inc/parser/parser_eol.test.php index 6264f8b55..3ae96ef62 100644 --- a/_test/tests/inc/parser/parser_eol.test.php +++ b/_test/tests/inc/parser/parser_eol.test.php @@ -1,10 +1,14 @@ <?php + +use dokuwiki\ParserMode\Eol; +use dokuwiki\ParserMode\Linebreak; + require_once 'parser.inc.php'; class TestOfDoku_Parser_Eol extends TestOfDoku_Parser { function testEol() { - $this->P->addMode('eol',new Doku_Parser_Mode_Eol()); + $this->P->addMode('eol',new Eol()); $this->P->parse("Foo\nBar"); $calls = array ( array('document_start',array()), @@ -17,7 +21,7 @@ class TestOfDoku_Parser_Eol extends TestOfDoku_Parser { } function testEolMultiple() { - $this->P->addMode('eol',new Doku_Parser_Mode_Eol()); + $this->P->addMode('eol',new Eol()); $this->P->parse("Foo\n\nbar\nFoo"); $calls = array ( array('document_start',array()), @@ -33,7 +37,7 @@ class TestOfDoku_Parser_Eol extends TestOfDoku_Parser { } function testWinEol() { - $this->P->addMode('eol',new Doku_Parser_Mode_Eol()); + $this->P->addMode('eol',new Eol()); $this->P->parse("Foo\r\nBar"); $calls = array ( array('document_start',array()), @@ -46,7 +50,7 @@ class TestOfDoku_Parser_Eol extends TestOfDoku_Parser { } function testLinebreak() { - $this->P->addMode('linebreak',new Doku_Parser_Mode_Linebreak()); + $this->P->addMode('linebreak',new Linebreak()); $this->P->parse('Foo\\\\ Bar'); $calls = array ( array('document_start',array()), @@ -61,8 +65,8 @@ class TestOfDoku_Parser_Eol extends TestOfDoku_Parser { } function testLinebreakPlusEol() { - $this->P->addMode('linebreak',new Doku_Parser_Mode_Linebreak()); - $this->P->addMode('eol',new Doku_Parser_Mode_Eol()); + $this->P->addMode('linebreak',new Linebreak()); + $this->P->addMode('eol',new Eol()); $this->P->parse('Foo\\\\'."\n\n".'Bar'); $calls = array ( @@ -80,7 +84,7 @@ class TestOfDoku_Parser_Eol extends TestOfDoku_Parser { } function testLinebreakInvalid() { - $this->P->addMode('linebreak',new Doku_Parser_Mode_Linebreak()); + $this->P->addMode('linebreak',new Linebreak()); $this->P->parse('Foo\\\\Bar'); $calls = array ( array('document_start',array()), diff --git a/_test/tests/inc/parser/parser_file.test.php b/_test/tests/inc/parser/parser_file.test.php index 39bda8a58..8c8caac85 100644 --- a/_test/tests/inc/parser/parser_file.test.php +++ b/_test/tests/inc/parser/parser_file.test.php @@ -1,11 +1,14 @@ <?php + +use dokuwiki\ParserMode\File; + require_once 'parser.inc.php'; class TestOfDoku_Parser_File extends TestOfDoku_Parser { function setUp() { parent::setUp(); - $this->P->addMode('file',new Doku_Parser_Mode_File()); + $this->P->addMode('file',new File()); } function testFile() { diff --git a/_test/tests/inc/parser/parser_footnote.test.php b/_test/tests/inc/parser/parser_footnote.test.php index 2457fb031..74f7c64f3 100644 --- a/_test/tests/inc/parser/parser_footnote.test.php +++ b/_test/tests/inc/parser/parser_footnote.test.php @@ -1,11 +1,23 @@ <?php + +use dokuwiki\ParserMode\Code; +use dokuwiki\ParserMode\Eol; +use dokuwiki\ParserMode\Footnote; +use dokuwiki\ParserMode\Formatting; +use dokuwiki\ParserMode\Hr; +use dokuwiki\ParserMode\Listblock; +use dokuwiki\ParserMode\Preformatted; +use dokuwiki\ParserMode\Quote; +use dokuwiki\ParserMode\Table; +use dokuwiki\ParserMode\Unformatted; + require_once 'parser.inc.php'; class TestOfDoku_Parser_Footnote extends TestOfDoku_Parser { function setUp() { parent::setUp(); - $this->P->addMode('footnote',new Doku_Parser_Mode_Footnote()); + $this->P->addMode('footnote',new Footnote()); } function testFootnote() { @@ -39,7 +51,7 @@ class TestOfDoku_Parser_Footnote extends TestOfDoku_Parser { } function testFootnoteLinefeed() { - $this->P->addMode('eol',new Doku_Parser_Mode_Eol()); + $this->P->addMode('eol',new Eol()); $this->P->parse("Foo (( testing\ntesting )) Bar"); $calls = array ( array('document_start',array()), @@ -76,7 +88,7 @@ class TestOfDoku_Parser_Footnote extends TestOfDoku_Parser { } function testFootnoteEol() { - $this->P->addMode('eol',new Doku_Parser_Mode_Eol()); + $this->P->addMode('eol',new Eol()); $this->P->parse("Foo \nX(( test\ning ))Y\n Bar"); $calls = array ( array('document_start',array()), @@ -95,7 +107,7 @@ class TestOfDoku_Parser_Footnote extends TestOfDoku_Parser { } function testFootnoteStrong() { - $this->P->addMode('strong',new Doku_Parser_Mode_Formatting('strong')); + $this->P->addMode('strong',new Formatting('strong')); $this->P->parse('Foo (( **testing** )) Bar'); $calls = array ( array('document_start',array()), @@ -118,7 +130,7 @@ class TestOfDoku_Parser_Footnote extends TestOfDoku_Parser { } function testFootnoteHr() { - $this->P->addMode('hr',new Doku_Parser_Mode_HR()); + $this->P->addMode('hr',new Hr()); $this->P->parse("Foo (( \n ---- \n )) Bar"); $calls = array ( array('document_start',array()), @@ -139,7 +151,7 @@ class TestOfDoku_Parser_Footnote extends TestOfDoku_Parser { } function testFootnoteCode() { - $this->P->addMode('code',new Doku_Parser_Mode_Code()); + $this->P->addMode('code',new Code()); $this->P->parse("Foo (( <code>Test</code> )) Bar"); $calls = array ( array('document_start',array()), @@ -160,7 +172,7 @@ class TestOfDoku_Parser_Footnote extends TestOfDoku_Parser { } function testFootnotePreformatted() { - $this->P->addMode('preformatted',new Doku_Parser_Mode_Preformatted()); + $this->P->addMode('preformatted',new Preformatted()); $this->P->parse("Foo (( \n Test\n )) Bar"); $calls = array ( array('document_start',array()), @@ -181,8 +193,8 @@ class TestOfDoku_Parser_Footnote extends TestOfDoku_Parser { } function testFootnotePreformattedEol() { - $this->P->addMode('preformatted',new Doku_Parser_Mode_Preformatted()); - $this->P->addMode('eol',new Doku_Parser_Mode_Eol()); + $this->P->addMode('preformatted',new Preformatted()); + $this->P->addMode('eol',new Eol()); $this->P->parse("Foo (( \n Test\n )) Bar"); $calls = array ( array('document_start',array()), @@ -204,7 +216,7 @@ class TestOfDoku_Parser_Footnote extends TestOfDoku_Parser { } function testFootnoteUnformatted() { - $this->P->addMode('unformatted',new Doku_Parser_Mode_Unformatted()); + $this->P->addMode('unformatted',new Unformatted()); $this->P->parse("Foo (( <nowiki>Test</nowiki> )) Bar"); $calls = array ( array('document_start',array()), @@ -225,7 +237,7 @@ class TestOfDoku_Parser_Footnote extends TestOfDoku_Parser { } function testFootnoteNotHeader() { - $this->P->addMode('unformatted',new Doku_Parser_Mode_Unformatted()); + $this->P->addMode('unformatted',new Unformatted()); $this->P->parse("Foo (( \n====Test====\n )) Bar"); $calls = array ( array('document_start',array()), @@ -244,7 +256,7 @@ class TestOfDoku_Parser_Footnote extends TestOfDoku_Parser { } function testFootnoteTable() { - $this->P->addMode('table',new Doku_Parser_Mode_Table()); + $this->P->addMode('table',new Table()); $this->P->parse("Foo (( | Row 0 Col 1 | Row 0 Col 2 | Row 0 Col 3 | | Row 1 Col 1 | Row 1 Col 2 | Row 1 Col 3 | @@ -290,7 +302,7 @@ class TestOfDoku_Parser_Footnote extends TestOfDoku_Parser { } function testFootnoteList() { - $this->P->addMode('listblock',new Doku_Parser_Mode_ListBlock()); + $this->P->addMode('listblock',new ListBlock()); $this->P->parse("Foo (( *A * B @@ -332,7 +344,7 @@ class TestOfDoku_Parser_Footnote extends TestOfDoku_Parser { } function testFootnoteQuote() { - $this->P->addMode('quote',new Doku_Parser_Mode_Quote()); + $this->P->addMode('quote',new Quote()); $this->P->parse("Foo (( > def >>ghi @@ -361,7 +373,7 @@ class TestOfDoku_Parser_Footnote extends TestOfDoku_Parser { } function testFootnoteNesting() { - $this->P->addMode('strong',new Doku_Parser_Mode_Formatting('strong')); + $this->P->addMode('strong',new Formatting('strong')); $this->P->parse("(( a ** (( b )) ** c ))"); $calls = array( diff --git a/_test/tests/inc/parser/parser_headers.test.php b/_test/tests/inc/parser/parser_headers.test.php index a1bf7d2ba..5c5936a82 100644 --- a/_test/tests/inc/parser/parser_headers.test.php +++ b/_test/tests/inc/parser/parser_headers.test.php @@ -1,10 +1,14 @@ <?php + +use dokuwiki\ParserMode\Eol; +use dokuwiki\ParserMode\Header; + require_once 'parser.inc.php'; class TestOfDoku_Parser_Headers extends TestOfDoku_Parser { function testHeader1() { - $this->P->addMode('header',new Doku_Parser_Mode_Header()); + $this->P->addMode('header',new Header()); $this->P->parse("abc \n ====== Header ====== \n def"); $calls = array ( array('document_start',array()), @@ -23,7 +27,7 @@ class TestOfDoku_Parser_Headers extends TestOfDoku_Parser { } function testHeader2() { - $this->P->addMode('header',new Doku_Parser_Mode_Header()); + $this->P->addMode('header',new Header()); $this->P->parse("abc \n ===== Header ===== \n def"); $calls = array ( array('document_start',array()), @@ -42,7 +46,7 @@ class TestOfDoku_Parser_Headers extends TestOfDoku_Parser { } function testHeader3() { - $this->P->addMode('header',new Doku_Parser_Mode_Header()); + $this->P->addMode('header',new Header()); $this->P->parse("abc \n ==== Header ==== \n def"); $calls = array ( array('document_start',array()), @@ -61,7 +65,7 @@ class TestOfDoku_Parser_Headers extends TestOfDoku_Parser { } function testHeader4() { - $this->P->addMode('header',new Doku_Parser_Mode_Header()); + $this->P->addMode('header',new Header()); $this->P->parse("abc \n === Header === \n def"); $calls = array ( array('document_start',array()), @@ -80,7 +84,7 @@ class TestOfDoku_Parser_Headers extends TestOfDoku_Parser { } function testHeader5() { - $this->P->addMode('header',new Doku_Parser_Mode_Header()); + $this->P->addMode('header',new Header()); $this->P->parse("abc \n == Header == \n def"); $calls = array ( array('document_start',array()), @@ -99,7 +103,7 @@ class TestOfDoku_Parser_Headers extends TestOfDoku_Parser { } function testHeader2UnevenSmaller() { - $this->P->addMode('header',new Doku_Parser_Mode_Header()); + $this->P->addMode('header',new Header()); $this->P->parse("abc \n ===== Header == \n def"); $calls = array ( array('document_start',array()), @@ -118,7 +122,7 @@ class TestOfDoku_Parser_Headers extends TestOfDoku_Parser { } function testHeader2UnevenBigger() { - $this->P->addMode('header',new Doku_Parser_Mode_Header()); + $this->P->addMode('header',new Header()); $this->P->parse("abc \n ===== Header =========== \n def"); $calls = array ( array('document_start',array()), @@ -137,7 +141,7 @@ class TestOfDoku_Parser_Headers extends TestOfDoku_Parser { } function testHeaderLarge() { - $this->P->addMode('header',new Doku_Parser_Mode_Header()); + $this->P->addMode('header',new Header()); $this->P->parse("abc \n ======= Header ======= \n def"); $calls = array ( array('document_start',array()), @@ -156,7 +160,7 @@ class TestOfDoku_Parser_Headers extends TestOfDoku_Parser { } function testHeaderSmall() { - $this->P->addMode('header',new Doku_Parser_Mode_Header()); + $this->P->addMode('header',new Header()); $this->P->parse("abc \n= Header =\n def"); $calls = array ( array('document_start',array()), @@ -170,7 +174,7 @@ class TestOfDoku_Parser_Headers extends TestOfDoku_Parser { function testHeader1Mixed() { - $this->P->addMode('header',new Doku_Parser_Mode_Header()); + $this->P->addMode('header',new Header()); $this->P->parse("abc \n====== == Header == ======\n def"); $calls = array ( array('document_start',array()), @@ -189,7 +193,7 @@ class TestOfDoku_Parser_Headers extends TestOfDoku_Parser { } function testHeader5Mixed() { - $this->P->addMode('header',new Doku_Parser_Mode_Header()); + $this->P->addMode('header',new Header()); $this->P->parse("abc \n== ====== Header ====== ==\n def"); $calls = array ( array('document_start',array()), @@ -208,7 +212,7 @@ class TestOfDoku_Parser_Headers extends TestOfDoku_Parser { } function testHeaderMultiline() { - $this->P->addMode('header',new Doku_Parser_Mode_Header()); + $this->P->addMode('header',new Header()); $this->P->parse("abc \n== ====== Header\n ====== ==\n def"); $calls = array ( array('document_start',array()), @@ -227,14 +231,14 @@ class TestOfDoku_Parser_Headers extends TestOfDoku_Parser { } # function testNoToc() { -# $this->P->addMode('notoc',new Doku_Parser_Mode_NoToc()); +# $this->P->addMode('notoc',new NoToc()); # $this->P->parse('abc ~~NOTOC~~ def'); # $this->assertFalse($this->H->meta['toc']); # } function testHeader1Eol() { - $this->P->addMode('header',new Doku_Parser_Mode_Header()); - $this->P->addMode('eol',new Doku_Parser_Mode_Eol()); + $this->P->addMode('header',new Header()); + $this->P->addMode('eol',new Eol()); $this->P->parse("abc \n ====== Header ====== \n def"); $calls = array ( array('document_start',array()), @@ -254,7 +258,7 @@ class TestOfDoku_Parser_Headers extends TestOfDoku_Parser { } function testHeaderMulti2() { - $this->P->addMode('header',new Doku_Parser_Mode_Header()); + $this->P->addMode('header',new Header()); $this->P->parse("abc \n ====== Header ====== \n def abc \n ===== Header2 ===== \n def"); $calls = array ( array('document_start',array()), diff --git a/_test/tests/inc/parser/parser_i18n.test.php b/_test/tests/inc/parser/parser_i18n.test.php index 096f2e227..b9fb64c4f 100644 --- a/_test/tests/inc/parser/parser_i18n.test.php +++ b/_test/tests/inc/parser/parser_i18n.test.php @@ -1,4 +1,11 @@ <?php + +use dokuwiki\ParserMode\Acronym; +use dokuwiki\ParserMode\Formatting; +use dokuwiki\ParserMode\Header; +use dokuwiki\ParserMode\Internallink; +use dokuwiki\ParserMode\Table; + require_once 'parser.inc.php'; class TestOfDoku_Parser_i18n extends TestOfDoku_Parser { @@ -9,7 +16,7 @@ class TestOfDoku_Parser_i18n extends TestOfDoku_Parser { 'subscript', 'superscript', 'deleted', ); foreach ( $formats as $format ) { - $this->P->addMode($format,new Doku_Parser_Mode_Formatting($format)); + $this->P->addMode($format,new Formatting($format)); } $this->P->parse("I**ñ**t__ë__r//n//â<sup>t</sup>i<sub>ô</sub>n''à''liz<del>æ</del>tiøn"); $calls = array ( @@ -51,7 +58,7 @@ class TestOfDoku_Parser_i18n extends TestOfDoku_Parser { } function testHeader() { - $this->P->addMode('header',new Doku_Parser_Mode_Header()); + $this->P->addMode('header',new Header()); $this->P->parse("Foo\n ==== Iñtërnâtiônàlizætiøn ==== \n Bar"); $calls = array ( array('document_start',array()), @@ -70,7 +77,7 @@ class TestOfDoku_Parser_i18n extends TestOfDoku_Parser { } function testTable() { - $this->P->addMode('table',new Doku_Parser_Mode_Table()); + $this->P->addMode('table',new Table()); $this->P->parse(' abc | Row 0 Col 1 | Iñtërnâtiônàlizætiøn | Row 0 Col 3 | @@ -115,7 +122,7 @@ def'); function testAcronym() { $t = array('Iñtërnâtiônàlizætiøn'); - $this->P->addMode('acronym',new Doku_Parser_Mode_Acronym($t)); + $this->P->addMode('acronym',new Acronym($t)); $this->P->parse("Foo Iñtërnâtiônàlizætiøn Bar"); $calls = array ( array('document_start',array()), @@ -130,7 +137,7 @@ def'); } function testInterwiki() { - $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); + $this->P->addMode('internallink',new InternalLink()); $this->P->parse("Foo [[wp>Iñtërnâtiônàlizætiøn|Iñtërnâtiônàlizætiøn]] Bar"); $calls = array ( array('document_start',array()), @@ -145,7 +152,7 @@ def'); } function testInternalLink() { - $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); + $this->P->addMode('internallink',new InternalLink()); $this->P->parse("Foo [[x:Iñtërnâtiônàlizætiøn:y:foo_bar:z|Iñtërnâtiônàlizætiøn]] Bar"); $calls = array ( array('document_start',array()), diff --git a/_test/tests/inc/parser/parser_links.test.php b/_test/tests/inc/parser/parser_links.test.php index ee001e73a..40d78da6b 100644 --- a/_test/tests/inc/parser/parser_links.test.php +++ b/_test/tests/inc/parser/parser_links.test.php @@ -1,4 +1,13 @@ <?php + +use dokuwiki\ParserMode\Camelcaselink; +use dokuwiki\ParserMode\Emaillink; +use dokuwiki\ParserMode\Externallink; +use dokuwiki\ParserMode\Filelink; +use dokuwiki\ParserMode\Internallink; +use dokuwiki\ParserMode\Media; +use dokuwiki\ParserMode\Windowssharelink; + require_once 'parser.inc.php'; /** @@ -9,7 +18,7 @@ require_once 'parser.inc.php'; class TestOfDoku_Parser_Links extends TestOfDoku_Parser { function testExternalLinkSimple() { - $this->P->addMode('externallink',new Doku_Parser_Mode_ExternalLink()); + $this->P->addMode('externallink',new Externallink()); $this->P->parse("Foo http://www.google.com Bar"); $calls = array ( array('document_start',array()), @@ -24,7 +33,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testExternalLinkCase() { - $this->P->addMode('externallink',new Doku_Parser_Mode_ExternalLink()); + $this->P->addMode('externallink',new Externallink()); $this->P->parse("Foo HTTP://WWW.GOOGLE.COM Bar"); $calls = array ( array('document_start',array()), @@ -39,7 +48,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testExternalIPv4() { - $this->P->addMode('externallink',new Doku_Parser_Mode_ExternalLink()); + $this->P->addMode('externallink',new Externallink()); $this->P->parse("Foo http://123.123.3.21/foo Bar"); $calls = array ( array('document_start',array()), @@ -54,7 +63,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testExternalIPv6() { - $this->P->addMode('externallink',new Doku_Parser_Mode_ExternalLink()); + $this->P->addMode('externallink',new Externallink()); $this->P->parse("Foo http://[3ffe:2a00:100:7031::1]/foo Bar"); $calls = array ( array('document_start',array()), @@ -96,8 +105,8 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { $name = $title; } $this->setup(); - $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); - $this->P->addMode('externallink',new Doku_Parser_Mode_ExternalLink()); + $this->P->addMode('internallink',new Internallink()); + $this->P->addMode('externallink',new Externallink()); $this->P->parse("Foo $source Bar"); $calls = array ( array('document_start',array()), @@ -117,7 +126,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testExternalLinkJavascript() { - $this->P->addMode('externallink',new Doku_Parser_Mode_ExternalLink()); + $this->P->addMode('externallink',new Externallink()); $this->P->parse("Foo javascript:alert('XSS'); Bar"); $calls = array ( array('document_start',array()), @@ -130,7 +139,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testExternalWWWLink() { - $this->P->addMode('externallink',new Doku_Parser_Mode_ExternalLink()); + $this->P->addMode('externallink',new Externallink()); $this->P->parse("Foo www.google.com Bar"); $calls = array ( array('document_start',array()), @@ -145,7 +154,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testExternalWWWLinkInPath() { - $this->P->addMode('externallink',new Doku_Parser_Mode_ExternalLink()); + $this->P->addMode('externallink',new Externallink()); // See issue #936. Should NOT generate a link! $this->P->parse("Foo /home/subdir/www/www.something.de/somedir/ Bar"); $calls = array ( @@ -159,7 +168,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testExternalWWWLinkFollowingPath() { - $this->P->addMode('externallink',new Doku_Parser_Mode_ExternalLink()); + $this->P->addMode('externallink',new Externallink()); $this->P->parse("Foo /home/subdir/www/ www.something.de/somedir/ Bar"); $calls = array ( array('document_start',array()), @@ -174,7 +183,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testExternalFTPLink() { - $this->P->addMode('externallink',new Doku_Parser_Mode_ExternalLink()); + $this->P->addMode('externallink',new Externallink()); $this->P->parse("Foo ftp.sunsite.com Bar"); $calls = array ( array('document_start',array()), @@ -189,7 +198,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testExternalFTPLinkInPath() { - $this->P->addMode('externallink',new Doku_Parser_Mode_ExternalLink()); + $this->P->addMode('externallink',new Externallink()); // See issue #936. Should NOT generate a link! $this->P->parse("Foo /home/subdir/www/ftp.something.de/somedir/ Bar"); $calls = array ( @@ -203,7 +212,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testExternalFTPLinkFollowingPath() { - $this->P->addMode('externallink',new Doku_Parser_Mode_ExternalLink()); + $this->P->addMode('externallink',new Externallink()); $this->P->parse("Foo /home/subdir/www/ ftp.something.de/somedir/ Bar"); $calls = array ( array('document_start',array()), @@ -218,7 +227,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testEmail() { - $this->P->addMode('emaillink',new Doku_Parser_Mode_Emaillink()); + $this->P->addMode('emaillink',new Emaillink()); $this->P->parse("Foo <bugs@php.net> Bar"); $calls = array ( array('document_start',array()), @@ -233,7 +242,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testEmailRFC2822() { - $this->P->addMode('emaillink',new Doku_Parser_Mode_Emaillink()); + $this->P->addMode('emaillink',new Emaillink()); $this->P->parse("Foo <~fix+bug's.for/ev{e}r@php.net> Bar"); $calls = array ( array('document_start',array()), @@ -248,7 +257,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testEmailCase() { - $this->P->addMode('emaillink',new Doku_Parser_Mode_Emaillink()); + $this->P->addMode('emaillink',new Emaillink()); $this->P->parse("Foo <bugs@pHp.net> Bar"); $calls = array ( array('document_start',array()), @@ -264,7 +273,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { function testInternalLinkOneChar() { - $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); + $this->P->addMode('internallink',new Internallink()); $this->P->parse("Foo [[l]] Bar"); $calls = array ( array('document_start',array()), @@ -279,7 +288,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testInternalLinkNoChar() { - $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); + $this->P->addMode('internallink',new Internallink()); $this->P->parse("Foo [[]] Bar"); $calls = array ( array('document_start',array()), @@ -294,7 +303,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testInternalLinkNamespaceNoTitle() { - $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); + $this->P->addMode('internallink',new Internallink()); $this->P->parse("Foo [[foo:bar]] Bar"); $calls = array ( array('document_start',array()), @@ -309,7 +318,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testInternalLinkNamespace() { - $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); + $this->P->addMode('internallink',new Internallink()); $this->P->parse("Foo [[x:1:y:foo_bar:z|Test]] Bar"); $calls = array ( array('document_start',array()), @@ -324,7 +333,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testInternalLinkSectionRef() { - $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); + $this->P->addMode('internallink',new Internallink()); $this->P->parse("Foo [[wiki:syntax#internal|Syntax]] Bar"); $calls = array ( array('document_start',array()), @@ -339,7 +348,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testInternalLinkCodeFollows() { - $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); + $this->P->addMode('internallink',new Internallink()); $this->P->parse("Foo [[wiki:internal:link|Test]] Bar <code>command [arg1 [arg2 [arg3]]]</code>"); $calls = array ( array('document_start',array()), @@ -354,7 +363,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testInternalLinkCodeFollows2() { - $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); + $this->P->addMode('internallink',new Internallink()); $this->P->parse("Foo [[wiki:internal:link|[Square brackets in title] Test]] Bar <code>command [arg1 [arg2 [arg3]]]</code>"); $calls = array ( array('document_start',array()), @@ -369,7 +378,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testExternalInInternalLink() { - $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); + $this->P->addMode('internallink',new Internallink()); $this->P->parse("Foo [[http://www.google.com|Google]] Bar"); $calls = array ( array('document_start',array()), @@ -384,7 +393,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testExternalInInternalLink2() { - $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); + $this->P->addMode('internallink',new Internallink()); $this->P->parse("Foo [[http://www.google.com?test[]=squarebracketsinurl|Google]] Bar"); $calls = array ( array('document_start',array()), @@ -399,7 +408,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testExternalInInternalLink2CodeFollows() { - $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); + $this->P->addMode('internallink',new Internallink()); $this->P->parse("Foo [[http://www.google.com?test[]=squarebracketsinurl|Google]] Bar <code>command [arg1 [arg2 [arg3]]]</code>"); $calls = array ( array('document_start',array()), @@ -414,7 +423,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testTwoInternalLinks() { - $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); + $this->P->addMode('internallink',new Internallink()); $this->P->parse("Foo [[foo:bar|one]] and [[bar:foo|two]] Bar"); $calls = array ( array('document_start',array()), @@ -432,7 +441,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { function testInterwikiLink() { - $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); + $this->P->addMode('internallink',new Internallink()); $this->P->parse("Foo [[iw>somepage|Some Page]] Bar"); $calls = array ( array('document_start',array()), @@ -447,7 +456,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testInterwikiLinkCase() { - $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); + $this->P->addMode('internallink',new Internallink()); $this->P->parse("Foo [[IW>somepage|Some Page]] Bar"); $calls = array ( array('document_start',array()), @@ -462,7 +471,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testInterwikiPedia() { - $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); + $this->P->addMode('internallink',new Internallink()); $this->P->parse("Foo [[wp>Callback_(computer_science)|callbacks]] Bar"); $calls = array ( array('document_start',array()), @@ -477,7 +486,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testCamelCase() { - $this->P->addMode('camelcaselink',new Doku_Parser_Mode_CamelCaseLink()); + $this->P->addMode('camelcaselink',new Camelcaselink()); $this->P->parse("Foo FooBar Bar"); $calls = array ( array('document_start',array()), @@ -492,7 +501,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testFileLink() { - $this->P->addMode('filelink',new Doku_Parser_Mode_FileLink()); + $this->P->addMode('filelink',new FileLink()); $this->P->parse('Foo file://temp/file.txt Bar'); $calls = array ( array('document_start',array()), @@ -507,7 +516,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testFileLinkInternal() { - $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); + $this->P->addMode('internallink',new Internallink()); $this->P->parse('Foo [[file://temp/file.txt|Some File]] Bar'); $calls = array ( array('document_start',array()), @@ -522,7 +531,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testWindowsShareLink() { - $this->P->addMode('windowssharelink',new Doku_Parser_Mode_WindowsShareLink()); + $this->P->addMode('windowssharelink',new Windowssharelink()); $this->P->parse('Foo \\\server\share Bar'); $calls = array ( array('document_start',array()), @@ -537,7 +546,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testWindowsShareLinkHyphen() { - $this->P->addMode('windowssharelink',new Doku_Parser_Mode_WindowsShareLink()); + $this->P->addMode('windowssharelink',new Windowssharelink()); $this->P->parse('Foo \\\server\share-hyphen Bar'); $calls = array ( array('document_start',array()), @@ -552,7 +561,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testWindowsShareLinkInternal() { - $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); + $this->P->addMode('internallink',new Internallink()); $this->P->parse('Foo [[\\\server\share|My Documents]] Bar'); $calls = array ( array('document_start',array()), @@ -567,7 +576,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testMediaInternal() { - $this->P->addMode('media',new Doku_Parser_Mode_Media()); + $this->P->addMode('media',new Media()); $this->P->parse('Foo {{img.gif}} Bar'); $calls = array ( array('document_start',array()), @@ -582,7 +591,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testMediaInternalLinkOnly() { - $this->P->addMode('media',new Doku_Parser_Mode_Media()); + $this->P->addMode('media',new Media()); $this->P->parse('Foo {{img.gif?linkonly}} Bar'); $calls = array ( array('document_start',array()), @@ -597,7 +606,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testMediaNotImage() { - $this->P->addMode('media',new Doku_Parser_Mode_Media()); + $this->P->addMode('media',new Media()); $this->P->parse('Foo {{foo.txt?10x10|Some File}} Bar'); $calls = array ( array('document_start',array()), @@ -612,7 +621,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testMediaInternalLAlign() { - $this->P->addMode('media',new Doku_Parser_Mode_Media()); + $this->P->addMode('media',new Media()); $this->P->parse('Foo {{img.gif }} Bar'); $calls = array ( array('document_start',array()), @@ -627,7 +636,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testMediaInternalRAlign() { - $this->P->addMode('media',new Doku_Parser_Mode_Media()); + $this->P->addMode('media',new Media()); $this->P->parse('Foo {{ img.gif}} Bar'); $calls = array ( array('document_start',array()), @@ -642,7 +651,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testMediaInternalCenter() { - $this->P->addMode('media',new Doku_Parser_Mode_Media()); + $this->P->addMode('media',new Media()); $this->P->parse('Foo {{ img.gif }} Bar'); $calls = array ( array('document_start',array()), @@ -657,7 +666,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testMediaInternalParams() { - $this->P->addMode('media',new Doku_Parser_Mode_Media()); + $this->P->addMode('media',new Media()); $this->P->parse('Foo {{img.gif?50x100nocache}} Bar'); $calls = array ( array('document_start',array()), @@ -672,7 +681,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testMediaInternalTitle() { - $this->P->addMode('media',new Doku_Parser_Mode_Media()); + $this->P->addMode('media',new Media()); $this->P->parse('Foo {{img.gif?50x100|Some Image}} Bar'); $calls = array ( array('document_start',array()), @@ -687,7 +696,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testMediaExternal() { - $this->P->addMode('media',new Doku_Parser_Mode_Media()); + $this->P->addMode('media',new Media()); $this->P->parse('Foo {{http://www.google.com/img.gif}} Bar'); $calls = array ( array('document_start',array()), @@ -702,7 +711,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testMediaExternalParams() { - $this->P->addMode('media',new Doku_Parser_Mode_Media()); + $this->P->addMode('media',new Media()); $this->P->parse('Foo {{http://www.google.com/img.gif?50x100nocache}} Bar'); $calls = array ( array('document_start',array()), @@ -717,7 +726,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testMediaExternalTitle() { - $this->P->addMode('media',new Doku_Parser_Mode_Media()); + $this->P->addMode('media',new Media()); $this->P->parse('Foo {{http://www.google.com/img.gif?50x100|Some Image}} Bar'); $calls = array ( array('document_start',array()), @@ -733,7 +742,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testMediaInInternalLink() { - $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); + $this->P->addMode('internallink',new Internallink()); $this->P->parse("Foo [[x:1:y:foo_bar:z|{{img.gif?10x20nocache|Some Image}}]] Bar"); $image = array( @@ -760,7 +769,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testMediaNoImageInInternalLink() { - $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); + $this->P->addMode('internallink',new Internallink()); $this->P->parse("Foo [[x:1:y:foo_bar:z|{{foo.txt?10x20nocache|Some Image}}]] Bar"); $image = array( @@ -787,7 +796,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testMediaInEmailLink() { - $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); + $this->P->addMode('internallink',new Internallink()); $this->P->parse("Foo [[foo@example.com|{{img.gif?10x20nocache|Some Image}}]] Bar"); $image = array( @@ -814,7 +823,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { } function testNestedMedia() { - $this->P->addMode('media',new Doku_Parser_Mode_Media()); + $this->P->addMode('media',new Media()); $this->P->parse('Foo {{img.gif|{{foo.gif|{{bar.gif|Bar}}}}}} Bar'); $calls = array ( array('document_start',array()), diff --git a/_test/tests/inc/parser/parser_lists.test.php b/_test/tests/inc/parser/parser_lists.test.php index 6acaff637..ee0493c9f 100644 --- a/_test/tests/inc/parser/parser_lists.test.php +++ b/_test/tests/inc/parser/parser_lists.test.php @@ -1,10 +1,18 @@ <?php + +use dokuwiki\ParserMode\Eol; +use dokuwiki\ParserMode\Footnote; +use dokuwiki\ParserMode\Formatting; +use dokuwiki\ParserMode\Linebreak; +use dokuwiki\ParserMode\Listblock; +use dokuwiki\ParserMode\Unformatted; + require_once 'parser.inc.php'; class TestOfDoku_Parser_Lists extends TestOfDoku_Parser { function testUnorderedList() { - $this->P->addMode('listblock',new Doku_Parser_Mode_ListBlock()); + $this->P->addMode('listblock',new Listblock()); $this->P->parse(' *A * B @@ -37,7 +45,7 @@ class TestOfDoku_Parser_Lists extends TestOfDoku_Parser { } function testOrderedList() { - $this->P->addMode('listblock',new Doku_Parser_Mode_ListBlock()); + $this->P->addMode('listblock',new Listblock()); $this->P->parse(' -A - B @@ -71,7 +79,7 @@ class TestOfDoku_Parser_Lists extends TestOfDoku_Parser { function testMixedList() { - $this->P->addMode('listblock',new Doku_Parser_Mode_ListBlock()); + $this->P->addMode('listblock',new Listblock()); $this->P->parse(' -A * B @@ -102,9 +110,9 @@ class TestOfDoku_Parser_Lists extends TestOfDoku_Parser { ); $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls); } - + function testUnorderedListWinEOL() { - $this->P->addMode('listblock',new Doku_Parser_Mode_ListBlock()); + $this->P->addMode('listblock',new Listblock()); $this->P->parse("\r\n *A\r\n * B\r\n * C\r\n"); $calls = array ( array('document_start',array()), @@ -131,9 +139,9 @@ class TestOfDoku_Parser_Lists extends TestOfDoku_Parser { ); $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls); } - + function testOrderedListWinEOL() { - $this->P->addMode('listblock',new Doku_Parser_Mode_ListBlock()); + $this->P->addMode('listblock',new Listblock()); $this->P->parse("\r\n -A\r\n - B\r\n - C\r\n"); $calls = array ( array('document_start',array()), @@ -160,9 +168,9 @@ class TestOfDoku_Parser_Lists extends TestOfDoku_Parser { ); $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls); } - + function testNotAList() { - $this->P->addMode('listblock',new Doku_Parser_Mode_ListBlock()); + $this->P->addMode('listblock',new Listblock()); $this->P->parse("Foo -bar *foo Bar"); $calls = array ( array('document_start',array()), @@ -173,10 +181,10 @@ class TestOfDoku_Parser_Lists extends TestOfDoku_Parser { ); $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls); } - + function testUnorderedListParagraph() { - $this->P->addMode('listblock',new Doku_Parser_Mode_ListBlock()); - $this->P->addMode('eol',new Doku_Parser_Mode_Eol()); + $this->P->addMode('listblock',new Listblock()); + $this->P->addMode('eol',new Eol()); $this->P->parse('Foo *A * B @@ -213,12 +221,12 @@ Bar'); ); $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls); } - + // This is really a failing test - formatting able to spread across list items // Problem is fixing it would mean a major rewrite of lists function testUnorderedListStrong() { - $this->P->addMode('listblock',new Doku_Parser_Mode_ListBlock()); - $this->P->addMode('strong',new Doku_Parser_Mode_Formatting('strong')); + $this->P->addMode('listblock',new Listblock()); + $this->P->addMode('strong',new Formatting('strong')); $this->P->parse(' ***A** *** B @@ -248,12 +256,12 @@ Bar'); ); $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls); } - + // This is really a failing test - unformatted able to spread across list items // Problem is fixing it would mean a major rewrite of lists function testUnorderedListUnformatted() { - $this->P->addMode('listblock',new Doku_Parser_Mode_ListBlock()); - $this->P->addMode('unformatted',new Doku_Parser_Mode_Unformatted()); + $this->P->addMode('listblock',new Listblock()); + $this->P->addMode('unformatted',new Unformatted()); $this->P->parse(' *%%A%% *%% B @@ -279,10 +287,10 @@ Bar'); ); $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls); } - + function testUnorderedListLinebreak() { - $this->P->addMode('listblock',new Doku_Parser_Mode_ListBlock()); - $this->P->addMode('linebreak',new Doku_Parser_Mode_Linebreak()); + $this->P->addMode('listblock',new Listblock()); + $this->P->addMode('linebreak',new Linebreak()); $this->P->parse(' *A\\\\ D * B @@ -315,10 +323,10 @@ Bar'); ); $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls); } - + function testUnorderedListLinebreak2() { - $this->P->addMode('listblock',new Doku_Parser_Mode_ListBlock()); - $this->P->addMode('linebreak',new Doku_Parser_Mode_Linebreak()); + $this->P->addMode('listblock',new Listblock()); + $this->P->addMode('linebreak',new Linebreak()); $this->P->parse(' *A\\\\ * B @@ -342,10 +350,10 @@ Bar'); ); $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls); } - + function testUnorderedListFootnote() { - $this->P->addMode('listblock',new Doku_Parser_Mode_ListBlock()); - $this->P->addMode('footnote',new Doku_Parser_Mode_Footnote()); + $this->P->addMode('listblock',new Listblock()); + $this->P->addMode('footnote',new Footnote()); $this->P->parse(' *((A)) *(( B diff --git a/_test/tests/inc/parser/parser_preformatted.test.php b/_test/tests/inc/parser/parser_preformatted.test.php index f7a01a7e5..f1eee24a1 100644 --- a/_test/tests/inc/parser/parser_preformatted.test.php +++ b/_test/tests/inc/parser/parser_preformatted.test.php @@ -1,10 +1,20 @@ <?php + +use dokuwiki\ParserMode\Code; +use dokuwiki\ParserMode\Eol; +use dokuwiki\ParserMode\File; +use dokuwiki\ParserMode\Header; +use dokuwiki\ParserMode\Html; +use dokuwiki\ParserMode\Listblock; +use dokuwiki\ParserMode\Php; +use dokuwiki\ParserMode\Preformatted; + require_once 'parser.inc.php'; class TestOfDoku_Parser_Preformatted extends TestOfDoku_Parser { function testFile() { - $this->P->addMode('file',new Doku_Parser_Mode_File()); + $this->P->addMode('file',new File()); $this->P->parse('Foo <file>testing</file> Bar'); $calls = array ( array('document_start',array()), @@ -22,7 +32,7 @@ class TestOfDoku_Parser_Preformatted extends TestOfDoku_Parser { } function testCode() { - $this->P->addMode('code',new Doku_Parser_Mode_Code()); + $this->P->addMode('code',new Code()); $this->P->parse('Foo <code>testing</code> Bar'); $calls = array ( array('document_start',array()), @@ -39,7 +49,7 @@ class TestOfDoku_Parser_Preformatted extends TestOfDoku_Parser { } function testCodeWhitespace() { - $this->P->addMode('code',new Doku_Parser_Mode_Code()); + $this->P->addMode('code',new Code()); $this->P->parse("Foo <code \n>testing</code> Bar"); $calls = array ( array('document_start',array()), @@ -56,7 +66,7 @@ class TestOfDoku_Parser_Preformatted extends TestOfDoku_Parser { } function testCodeLang() { - $this->P->addMode('code',new Doku_Parser_Mode_Code()); + $this->P->addMode('code',new Code()); $this->P->parse("Foo <code php>testing</code> Bar"); $calls = array ( array('document_start',array()), @@ -73,7 +83,7 @@ class TestOfDoku_Parser_Preformatted extends TestOfDoku_Parser { } function testPreformatted() { - $this->P->addMode('preformatted',new Doku_Parser_Mode_Preformatted()); + $this->P->addMode('preformatted',new Preformatted()); $this->P->parse("F oo\n x \n y \nBar\n"); $calls = array ( array('document_start',array()), @@ -90,7 +100,7 @@ class TestOfDoku_Parser_Preformatted extends TestOfDoku_Parser { } function testPreformattedWinEOL() { - $this->P->addMode('preformatted',new Doku_Parser_Mode_Preformatted()); + $this->P->addMode('preformatted',new Preformatted()); $this->P->parse("F oo\r\n x \r\n y \r\nBar\r\n"); $calls = array ( array('document_start',array()), @@ -107,7 +117,7 @@ class TestOfDoku_Parser_Preformatted extends TestOfDoku_Parser { } function testPreformattedTab() { - $this->P->addMode('preformatted',new Doku_Parser_Mode_Preformatted()); + $this->P->addMode('preformatted',new Preformatted()); $this->P->parse("F oo\n\tx\t\n\t\ty\t\nBar\n"); $calls = array ( array('document_start',array()), @@ -124,7 +134,7 @@ class TestOfDoku_Parser_Preformatted extends TestOfDoku_Parser { } function testPreformattedTabWinEOL() { - $this->P->addMode('preformatted',new Doku_Parser_Mode_Preformatted()); + $this->P->addMode('preformatted',new Preformatted()); $this->P->parse("F oo\r\n\tx\t\r\n\t\ty\t\r\nBar\r\n"); $calls = array ( array('document_start',array()), @@ -141,8 +151,8 @@ class TestOfDoku_Parser_Preformatted extends TestOfDoku_Parser { } function testPreformattedList() { - $this->P->addMode('preformatted',new Doku_Parser_Mode_Preformatted()); - $this->P->addMode('listblock',new Doku_Parser_Mode_ListBlock()); + $this->P->addMode('preformatted',new Preformatted()); + $this->P->addMode('listblock',new Listblock()); $this->P->parse(" - x \n * y \nF oo\n x \n y \n -X\n *Y\nBar\n"); $calls = array ( array('document_start',array()), @@ -175,7 +185,7 @@ class TestOfDoku_Parser_Preformatted extends TestOfDoku_Parser { // test for php function testPHP() { - $this->P->addMode('php',new Doku_Parser_Mode_PHP()); + $this->P->addMode('php',new Php()); $this->P->parse('Foo <php>testing</php> Bar'); $calls = array ( array('document_start',array()), @@ -192,7 +202,7 @@ class TestOfDoku_Parser_Preformatted extends TestOfDoku_Parser { // test with for HTML function testHTML() { - $this->P->addMode('html',new Doku_Parser_Mode_HTML()); + $this->P->addMode('html',new Html()); $this->P->parse('Foo <html>testing</html> Bar'); $calls = array ( array('document_start',array()), @@ -210,9 +220,9 @@ class TestOfDoku_Parser_Preformatted extends TestOfDoku_Parser { function testPreformattedPlusHeaderAndEol() { // Note that EOL must come after preformatted! - $this->P->addMode('preformatted',new Doku_Parser_Mode_Preformatted()); - $this->P->addMode('header',new Doku_Parser_Mode_Header()); - $this->P->addMode('eol',new Doku_Parser_Mode_Eol()); + $this->P->addMode('preformatted',new Preformatted()); + $this->P->addMode('header',new Header()); + $this->P->addMode('eol',new Eol()); $this->P->parse("F oo\n ==Test==\n y \nBar\n"); $calls = array ( array('document_start',array()), diff --git a/_test/tests/inc/parser/parser_quote.test.php b/_test/tests/inc/parser/parser_quote.test.php index ae14671c1..6fa348671 100644 --- a/_test/tests/inc/parser/parser_quote.test.php +++ b/_test/tests/inc/parser/parser_quote.test.php @@ -1,10 +1,14 @@ <?php + +use dokuwiki\ParserMode\Eol; +use dokuwiki\ParserMode\Quote; + require_once 'parser.inc.php'; class TestOfDoku_Parser_Quote extends TestOfDoku_Parser { function testQuote() { - $this->P->addMode('quote',new Doku_Parser_Mode_Quote()); + $this->P->addMode('quote',new Quote()); $this->P->parse("abc\n> def\n>>ghi\nklm"); $calls = array ( array('document_start',array()), @@ -27,7 +31,7 @@ class TestOfDoku_Parser_Quote extends TestOfDoku_Parser { } function testQuoteWinCr() { - $this->P->addMode('quote',new Doku_Parser_Mode_Quote()); + $this->P->addMode('quote',new Quote()); $this->P->parse("abc\r\n> def\r\n>>ghi\r\nklm"); $calls = array ( array('document_start',array()), @@ -50,7 +54,7 @@ class TestOfDoku_Parser_Quote extends TestOfDoku_Parser { } function testQuoteMinumumContext() { - $this->P->addMode('quote',new Doku_Parser_Mode_Quote()); + $this->P->addMode('quote',new Quote()); $this->P->parse("\n> def\n>>ghi\n "); $calls = array ( array('document_start',array()), @@ -67,8 +71,8 @@ class TestOfDoku_Parser_Quote extends TestOfDoku_Parser { } function testQuoteEol() { - $this->P->addMode('quote',new Doku_Parser_Mode_Quote()); - $this->P->addMode('eol',new Doku_Parser_Mode_Eol()); + $this->P->addMode('quote',new Quote()); + $this->P->addMode('eol',new Eol()); $this->P->parse("abc\n> def\n>>ghi\nklm"); $calls = array ( array('document_start',array()), diff --git a/_test/tests/inc/parser/parser_quotes.test.php b/_test/tests/inc/parser/parser_quotes.test.php index 6f174ddae..46f87939b 100644 --- a/_test/tests/inc/parser/parser_quotes.test.php +++ b/_test/tests/inc/parser/parser_quotes.test.php @@ -1,4 +1,7 @@ <?php + +use dokuwiki\ParserMode\Quotes; + require_once 'parser.inc.php'; class TestOfDoku_Parser_Quotes extends TestOfDoku_Parser { @@ -11,7 +14,7 @@ class TestOfDoku_Parser_Quotes extends TestOfDoku_Parser { function testSingleQuoteOpening() { $raw = "Foo 'hello Bar"; - $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->addMode('quotes',new Quotes()); $this->P->parse($raw); $calls = array ( @@ -29,7 +32,7 @@ class TestOfDoku_Parser_Quotes extends TestOfDoku_Parser { function testSingleQuoteOpeningSpecial() { $raw = "Foo said:'hello Bar"; - $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->addMode('quotes',new Quotes()); $this->P->parse($raw); $calls = array ( @@ -47,7 +50,7 @@ class TestOfDoku_Parser_Quotes extends TestOfDoku_Parser { function testSingleQuoteClosing() { $raw = "Foo hello' Bar"; - $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->addMode('quotes',new Quotes()); $this->P->parse($raw); $calls = array ( @@ -65,7 +68,7 @@ class TestOfDoku_Parser_Quotes extends TestOfDoku_Parser { function testSingleQuoteClosingSpecial() { $raw = "Foo hello') Bar"; - $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->addMode('quotes',new Quotes()); $this->P->parse($raw); $calls = array ( @@ -83,7 +86,7 @@ class TestOfDoku_Parser_Quotes extends TestOfDoku_Parser { function testSingleQuotes() { $raw = "Foo 'hello' Bar"; - $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->addMode('quotes',new Quotes()); $this->P->parse($raw); $calls = array ( @@ -103,7 +106,7 @@ class TestOfDoku_Parser_Quotes extends TestOfDoku_Parser { function testApostrophe() { $raw = "hey it's fine weather today"; - $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->addMode('quotes',new Quotes()); $this->P->parse($raw); $calls = array ( @@ -122,7 +125,7 @@ class TestOfDoku_Parser_Quotes extends TestOfDoku_Parser { function testSingleQuotesSpecial() { $raw = "Foo ('hello') Bar"; - $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->addMode('quotes',new Quotes()); $this->P->parse($raw); $calls = array ( @@ -142,7 +145,7 @@ class TestOfDoku_Parser_Quotes extends TestOfDoku_Parser { function testDoubleQuoteOpening() { $raw = 'Foo "hello Bar'; - $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->addMode('quotes',new Quotes()); $this->P->parse($raw); $calls = array ( @@ -160,7 +163,7 @@ class TestOfDoku_Parser_Quotes extends TestOfDoku_Parser { function testDoubleQuoteOpeningSpecial() { $raw = 'Foo said:"hello Bar'; - $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->addMode('quotes',new Quotes()); $this->P->parse($raw); $calls = array ( @@ -178,7 +181,7 @@ class TestOfDoku_Parser_Quotes extends TestOfDoku_Parser { function testDoubleQuoteClosing() { $raw = 'Foo hello" Bar'; - $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->addMode('quotes',new Quotes()); $this->H->status['doublequote'] = 1; $this->P->parse($raw); @@ -197,7 +200,7 @@ class TestOfDoku_Parser_Quotes extends TestOfDoku_Parser { function testDoubleQuoteClosingSpecial() { $raw = 'Foo hello") Bar'; - $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->addMode('quotes',new Quotes()); $this->H->status['doublequote'] = 1; $this->P->parse($raw); @@ -215,7 +218,7 @@ class TestOfDoku_Parser_Quotes extends TestOfDoku_Parser { } function testDoubleQuoteClosingSpecial2() { $raw = 'Foo hello") Bar'; - $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->addMode('quotes',new Quotes()); $this->H->status['doublequote'] = 0; $this->P->parse($raw); @@ -234,7 +237,7 @@ class TestOfDoku_Parser_Quotes extends TestOfDoku_Parser { function testDoubleQuotes() { $raw = 'Foo "hello" Bar'; - $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->addMode('quotes',new Quotes()); $this->P->parse($raw); $calls = array ( @@ -254,7 +257,7 @@ class TestOfDoku_Parser_Quotes extends TestOfDoku_Parser { function testDoubleQuotesSpecial() { $raw = 'Foo ("hello") Bar'; - $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->addMode('quotes',new Quotes()); $this->P->parse($raw); $calls = array ( @@ -274,7 +277,7 @@ class TestOfDoku_Parser_Quotes extends TestOfDoku_Parser { function testDoubleQuotesEnclosingBrackets() { $raw = 'Foo "{hello}" Bar'; - $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->addMode('quotes',new Quotes()); $this->P->parse($raw); $calls = array ( @@ -294,7 +297,7 @@ class TestOfDoku_Parser_Quotes extends TestOfDoku_Parser { function testDoubleQuotesEnclosingLink() { $raw = 'Foo "[[www.domain.com]]" Bar'; - $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->addMode('quotes',new Quotes()); $this->P->parse($raw); $calls = array ( @@ -315,7 +318,7 @@ class TestOfDoku_Parser_Quotes extends TestOfDoku_Parser { function testAllQuotes() { $raw = 'There was written "He thought \'It\'s a man\'s world\'".'; - $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->addMode('quotes',new Quotes()); $this->P->parse($raw); $calls = array ( diff --git a/_test/tests/inc/parser/parser_replacements.test.php b/_test/tests/inc/parser/parser_replacements.test.php index f0367dac0..46f14c799 100644 --- a/_test/tests/inc/parser/parser_replacements.test.php +++ b/_test/tests/inc/parser/parser_replacements.test.php @@ -1,10 +1,18 @@ <?php + +use dokuwiki\ParserMode\Acronym; +use dokuwiki\ParserMode\Entity; +use dokuwiki\ParserMode\Hr; +use dokuwiki\ParserMode\Multiplyentity; +use dokuwiki\ParserMode\Smiley; +use dokuwiki\ParserMode\Wordblock; + require_once 'parser.inc.php'; class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { function testSingleAcronym() { - $this->P->addMode('acronym',new Doku_Parser_Mode_Acronym(array('FOOBAR'))); + $this->P->addMode('acronym',new Acronym(array('FOOBAR'))); $this->P->parse('abc FOOBAR xyz'); $calls = array ( @@ -21,7 +29,7 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { } function testAlmostAnAcronym() { - $this->P->addMode('acronym',new Doku_Parser_Mode_Acronym(array('FOOBAR'))); + $this->P->addMode('acronym',new Acronym(array('FOOBAR'))); $this->P->parse('abcFOOBARxyz'); $calls = array ( @@ -36,7 +44,7 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { } function testPickAcronymCorrectly() { - $this->P->addMode('acronym',new Doku_Parser_Mode_Acronym(array('FOO'))); + $this->P->addMode('acronym',new Acronym(array('FOO'))); $this->P->parse('FOOBAR FOO'); $calls = array ( @@ -53,7 +61,7 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { } function testMultipleAcronyms() { - $this->P->addMode('acronym',new Doku_Parser_Mode_Acronym(array('FOO','BAR'))); + $this->P->addMode('acronym',new Acronym(array('FOO','BAR'))); $this->P->parse('abc FOO def BAR xyz'); $calls = array ( @@ -73,7 +81,7 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { } function testMultipleAcronymsWithSubset1() { - $this->P->addMode('acronym',new Doku_Parser_Mode_Acronym(array('FOO','A.FOO','FOO.1','A.FOO.1'))); + $this->P->addMode('acronym',new Acronym(array('FOO','A.FOO','FOO.1','A.FOO.1'))); $this->P->parse('FOO A.FOO FOO.1 A.FOO.1'); $calls = array ( @@ -96,7 +104,7 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { } function testMultipleAcronymsWithSubset2() { - $this->P->addMode('acronym',new Doku_Parser_Mode_Acronym(array('A.FOO.1','FOO.1','A.FOO','FOO'))); + $this->P->addMode('acronym',new Acronym(array('A.FOO.1','FOO.1','A.FOO','FOO'))); $this->P->parse('FOO A.FOO FOO.1 A.FOO.1'); $calls = array ( @@ -119,7 +127,7 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { } function testSingleSmileyFail() { - $this->P->addMode('smiley',new Doku_Parser_Mode_Smiley(array(':-)'))); + $this->P->addMode('smiley',new Smiley(array(':-)'))); $this->P->parse('abc:-)xyz'); $calls = array ( @@ -134,7 +142,7 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { } function testSingleSmiley() { - $this->P->addMode('smiley',new Doku_Parser_Mode_Smiley(array(':-)'))); + $this->P->addMode('smiley',new Smiley(array(':-)'))); $this->P->parse('abc :-) xyz'); $calls = array ( @@ -151,7 +159,7 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { } function testMultipleSmileysFail() { - $this->P->addMode('smiley',new Doku_Parser_Mode_Smiley(array(':-)','^_^'))); + $this->P->addMode('smiley',new Smiley(array(':-)','^_^'))); $this->P->parse('abc:-)x^_^yz'); $calls = array ( @@ -166,7 +174,7 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { } function testMultipleSmileys() { - $this->P->addMode('smiley',new Doku_Parser_Mode_Smiley(array(':-)','^_^'))); + $this->P->addMode('smiley',new Smiley(array(':-)','^_^'))); $this->P->parse('abc :-) x ^_^ yz'); $calls = array ( @@ -186,7 +194,7 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { function testBackslashSmileyFail() { // This smiley is really :-\\ but escaping makes like interesting - $this->P->addMode('smiley',new Doku_Parser_Mode_Smiley(array(':-\\\\'))); + $this->P->addMode('smiley',new Smiley(array(':-\\\\'))); $this->P->parse('abc:-\\\xyz'); $calls = array ( @@ -202,7 +210,7 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { function testBackslashSmiley() { // This smiley is really :-\\ but escaping makes like interesting - $this->P->addMode('smiley',new Doku_Parser_Mode_Smiley(array(':-\\\\'))); + $this->P->addMode('smiley',new Smiley(array(':-\\\\'))); $this->P->parse('abc :-\\\ xyz'); $calls = array ( @@ -219,7 +227,7 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { } function testSingleWordblock() { - $this->P->addMode('wordblock',new Doku_Parser_Mode_Wordblock(array('CAT'))); + $this->P->addMode('wordblock',new Wordblock(array('CAT'))); $this->P->parse('abc CAT xyz'); $calls = array ( @@ -236,7 +244,7 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { } function testWordblockCase() { - $this->P->addMode('wordblock',new Doku_Parser_Mode_Wordblock(array('CAT'))); + $this->P->addMode('wordblock',new Wordblock(array('CAT'))); $this->P->parse('abc cat xyz'); $calls = array ( @@ -253,7 +261,7 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { } function testMultipleWordblock() { - $this->P->addMode('wordblock',new Doku_Parser_Mode_Wordblock(array('CAT','dog'))); + $this->P->addMode('wordblock',new Wordblock(array('CAT','dog'))); $this->P->parse('abc cat x DOG yz'); $calls = array ( @@ -272,7 +280,7 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { } function testSingleEntity() { - $this->P->addMode('entity',new Doku_Parser_Mode_Entity(array('->'))); + $this->P->addMode('entity',new Entity(array('->'))); $this->P->parse('x -> y'); $calls = array ( @@ -289,7 +297,7 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { } function testMultipleEntities() { - $this->P->addMode('entity',new Doku_Parser_Mode_Entity(array('->','<-'))); + $this->P->addMode('entity',new Entity(array('->','<-'))); $this->P->parse('x -> y <- z'); $calls = array ( @@ -308,7 +316,7 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { } function testMultiplyEntity() { - $this->P->addMode('multiplyentity',new Doku_Parser_Mode_MultiplyEntity()); + $this->P->addMode('multiplyentity',new Multiplyentity()); $this->P->parse('Foo 10x20 Bar'); $calls = array ( @@ -326,7 +334,7 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { function testMultiplyEntityHex() { // the multiply entity pattern should not match hex numbers, eg. 0x123 - $this->P->addMode('multiplyentity',new Doku_Parser_Mode_MultiplyEntity()); + $this->P->addMode('multiplyentity',new Multiplyentity()); $this->P->parse('Foo 0x123 Bar'); $calls = array ( @@ -341,7 +349,7 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { } function testHR() { - $this->P->addMode('hr',new Doku_Parser_Mode_HR()); + $this->P->addMode('hr',new Hr()); $this->P->parse("Foo \n ---- \n Bar"); $calls = array ( @@ -359,7 +367,7 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { } function testHREol() { - $this->P->addMode('hr',new Doku_Parser_Mode_HR()); + $this->P->addMode('hr',new Hr()); $this->P->parse("Foo \n----\n Bar"); $calls = array ( diff --git a/_test/tests/inc/parser/parser_table.test.php b/_test/tests/inc/parser/parser_table.test.php index f05dd29aa..7c3421a1e 100644 --- a/_test/tests/inc/parser/parser_table.test.php +++ b/_test/tests/inc/parser/parser_table.test.php @@ -1,10 +1,18 @@ <?php + +use dokuwiki\ParserMode\Eol; +use dokuwiki\ParserMode\Footnote; +use dokuwiki\ParserMode\Formatting; +use dokuwiki\ParserMode\Linebreak; +use dokuwiki\ParserMode\Table; +use dokuwiki\ParserMode\Unformatted; + require_once 'parser.inc.php'; class TestOfDoku_Parser_Table extends TestOfDoku_Parser { function testTable() { - $this->P->addMode('table',new Doku_Parser_Mode_Table()); + $this->P->addMode('table',new Table()); $this->P->parse(' abc | Row 0 Col 1 | Row 0 Col 2 | Row 0 Col 3 | @@ -48,7 +56,7 @@ def'); } function testTableWinEOL() { - $this->P->addMode('table',new Doku_Parser_Mode_Table()); + $this->P->addMode('table',new Table()); $this->P->parse("\r\nabc\r\n| Row 0 Col 1 | Row 0 Col 2 | Row 0 Col 3 |\r\n| Row 1 Col 1 | Row 1 Col 2 | Row 1 Col 3 |\r\ndef"); $calls = array ( array('document_start',array()), @@ -88,7 +96,7 @@ def'); } function testEmptyTable() { - $this->P->addMode('table',new Doku_Parser_Mode_Table()); + $this->P->addMode('table',new Table()); $this->P->parse(' abc | @@ -113,7 +121,7 @@ def'); } function testTableHeaders() { - $this->P->addMode('table',new Doku_Parser_Mode_Table()); + $this->P->addMode('table',new Table()); $this->P->parse(' abc ^ X | Y ^ Z | @@ -148,7 +156,7 @@ def'); } function testTableHead() { - $this->P->addMode('table',new Doku_Parser_Mode_Table()); + $this->P->addMode('table',new Table()); $this->P->parse(' abc ^ X ^ Y ^ Z ^ @@ -197,7 +205,7 @@ def'); } function testTableHeadOneRowTable() { - $this->P->addMode('table',new Doku_Parser_Mode_Table()); + $this->P->addMode('table',new Table()); $this->P->parse(' abc ^ X ^ Y ^ Z ^ @@ -232,7 +240,7 @@ def'); } function testTableHeadMultiline() { - $this->P->addMode('table',new Doku_Parser_Mode_Table()); + $this->P->addMode('table',new Table()); $this->P->parse(' abc ^ X1 ^ Y1 ^ Z1 ^ @@ -293,7 +301,7 @@ def'); } function testCellAlignment() { - $this->P->addMode('table',new Doku_Parser_Mode_Table()); + $this->P->addMode('table',new Table()); $this->P->parse(' abc | X | Y ^ Z | @@ -327,7 +335,7 @@ def'); } function testCellSpan() { - $this->P->addMode('table',new Doku_Parser_Mode_Table()); + $this->P->addMode('table',new Table()); $this->P->parse(' abc | d || e | @@ -369,7 +377,7 @@ def'); } function testCellRowSpan() { - $this->P->addMode('table',new Doku_Parser_Mode_Table()); + $this->P->addMode('table',new Table()); $this->P->parse(' abc | a | c:::|| @@ -417,7 +425,7 @@ def'); } function testCellRowSpanFirstRow() { - $this->P->addMode('table',new Doku_Parser_Mode_Table()); + $this->P->addMode('table',new Table()); $this->P->parse(' abc |::: ^ d:::^:::| ::: | @@ -475,7 +483,7 @@ def'); } function testRowSpanTableHead() { - $this->P->addMode('table',new Doku_Parser_Mode_Table()); + $this->P->addMode('table',new Table()); $this->P->parse(' abc ^ X1 ^ Y1 ^ Z1 ^ @@ -533,7 +541,7 @@ def'); } function testRowSpanAcrossTableHeadBoundary() { - $this->P->addMode('table',new Doku_Parser_Mode_Table()); + $this->P->addMode('table',new Table()); $this->P->parse(' abc ^ X1 ^ Y1 ^ Z1 ^ @@ -600,8 +608,8 @@ def'); } function testCellAlignmentFormatting() { - $this->P->addMode('table',new Doku_Parser_Mode_Table()); - $this->P->addMode('strong',new Doku_Parser_Mode_Formatting('strong')); + $this->P->addMode('table',new Table()); + $this->P->addMode('strong',new Formatting('strong')); $this->P->parse(' abc | **X** | Y ^ Z | @@ -640,8 +648,8 @@ def'); } function testTableEol() { - $this->P->addMode('table',new Doku_Parser_Mode_Table()); - $this->P->addMode('eol',new Doku_Parser_Mode_Eol()); + $this->P->addMode('table',new Table()); + $this->P->addMode('eol',new Eol()); $this->P->parse(' abc | Row 0 Col 1 | Row 0 Col 2 | Row 0 Col 3 | @@ -687,8 +695,8 @@ def'); // This is really a failing test - formatting able to spread across cols // Problem is fixing it would mean a major rewrite of table handling function testTableStrong() { - $this->P->addMode('table',new Doku_Parser_Mode_Table()); - $this->P->addMode('strong',new Doku_Parser_Mode_Formatting('strong')); + $this->P->addMode('table',new Table()); + $this->P->addMode('strong',new Formatting('strong')); $this->P->parse(' abc | **Row 0 Col 1** | **Row 0 Col 2 | Row 0 Col 3** | @@ -742,8 +750,8 @@ def'); // This is really a failing test - unformatted able to spread across cols // Problem is fixing it would mean a major rewrite of table handling function testTableUnformatted() { - $this->P->addMode('table',new Doku_Parser_Mode_Table()); - $this->P->addMode('unformatted',new Doku_Parser_Mode_Unformatted()); + $this->P->addMode('table',new Table()); + $this->P->addMode('unformatted',new Unformatted()); $this->P->parse(' abc | <nowiki>Row 0 Col 1</nowiki> | <nowiki>Row 0 Col 2 | Row 0 Col 3</nowiki> | @@ -791,8 +799,8 @@ def'); } function testTableLinebreak() { - $this->P->addMode('table',new Doku_Parser_Mode_Table()); - $this->P->addMode('linebreak',new Doku_Parser_Mode_Linebreak()); + $this->P->addMode('table',new Table()); + $this->P->addMode('linebreak',new Linebreak()); $this->P->parse(' abc | Row 0\\\\ Col 1 | Row 0 Col 2 | Row 0 Col 3 | @@ -841,8 +849,8 @@ def'); // This is really a failing test - footnote able to spread across cols // Problem is fixing it would mean a major rewrite of table handling function testTableFootnote() { - $this->P->addMode('table',new Doku_Parser_Mode_Table()); - $this->P->addMode('footnote',new Doku_Parser_Mode_Footnote()); + $this->P->addMode('table',new Table()); + $this->P->addMode('footnote',new Footnote()); $this->P->parse(' abc | ((Row 0 Col 1)) | ((Row 0 Col 2 | Row 0 Col 3)) | @@ -899,7 +907,7 @@ def'); function testTable_FS1833() { $syntax = " \n| Row 0 Col 1 |\n"; - $this->P->addMode('table',new Doku_Parser_Mode_Table()); + $this->P->addMode('table',new Table()); $this->P->parse($syntax); $calls = array ( array('document_start',array()), @@ -920,7 +928,7 @@ def'); */ function testTable_CellFix() { $syntax = "\n| r1c1 | r1c2 | r1c3 |\n| r2c1 |\n"; - $this->P->addMode('table',new Doku_Parser_Mode_Table()); + $this->P->addMode('table',new Table()); $this->P->parse($syntax); $calls = array ( array('document_start',array()), @@ -961,7 +969,7 @@ def'); */ function testTable_CellFix2() { $syntax = "\n| r1c1 |\n| r2c1 | r2c2 | r2c3 |\n"; - $this->P->addMode('table',new Doku_Parser_Mode_Table()); + $this->P->addMode('table',new Table()); $this->P->parse($syntax); $calls = array ( array('document_start',array()), diff --git a/_test/tests/inc/parser/parser_unformatted.test.php b/_test/tests/inc/parser/parser_unformatted.test.php index f20ba5e8b..013cac80f 100644 --- a/_test/tests/inc/parser/parser_unformatted.test.php +++ b/_test/tests/inc/parser/parser_unformatted.test.php @@ -1,10 +1,13 @@ <?php + +use dokuwiki\ParserMode\Unformatted; + require_once 'parser.inc.php'; class TestOfDoku_Parser_Unformatted extends TestOfDoku_Parser { function testNowiki() { - $this->P->addMode('unformatted',new Doku_Parser_Mode_Unformatted()); + $this->P->addMode('unformatted',new Unformatted()); $this->P->parse("Foo <nowiki>testing</nowiki> Bar"); $calls = array ( array('document_start',array()), @@ -21,7 +24,7 @@ class TestOfDoku_Parser_Unformatted extends TestOfDoku_Parser { } function testDoublePercent() { - $this->P->addMode('unformatted',new Doku_Parser_Mode_Unformatted()); + $this->P->addMode('unformatted',new Unformatted()); $this->P->parse("Foo %%testing%% Bar"); $calls = array ( array('document_start',array()), 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; + } +} diff --git a/inc/parser/parser.php b/inc/parser/parser.php index f35a0b0dc..feafc8f62 100644 --- a/inc/parser/parser.php +++ b/inc/parser/parser.php @@ -1,4 +1,8 @@ <?php + +use dokuwiki\ParserMode\Base; +use dokuwiki\ParserMode\ModeInterface; + /** * Define various types of modes used by the parser - they are used to * populate the list of modes another mode accepts @@ -57,7 +61,7 @@ class Doku_Parser { var $connected = false; /** - * @param Doku_Parser_Mode_base $BaseMode + * @param Base $BaseMode */ function addBaseMode($BaseMode) { $this->modes['base'] = $BaseMode; @@ -72,11 +76,11 @@ class Doku_Parser { * Mode sequence is important * * @param string $name - * @param Doku_Parser_Mode_Interface $Mode + * @param ModeInterface $Mode */ - function addMode($name, Doku_Parser_Mode_Interface $Mode) { + function addMode($name, ModeInterface $Mode) { if ( !isset($this->modes['base']) ) { - $this->addBaseMode(new Doku_Parser_Mode_base()); + $this->addBaseMode(new Base()); } $Mode->Lexer = $this->Lexer; $this->modes[$name] = $Mode; @@ -125,906 +129,5 @@ class Doku_Parser { } -//------------------------------------------------------------------- - -/** - * Class Doku_Parser_Mode_Interface - * - * Defines a mode (syntax component) in the Parser - */ -interface Doku_Parser_Mode_Interface { - /** - * returns a number used to determine in which order modes are added - */ - public function getSort(); - - /** - * Called before any calls to connectTo - * @return void - */ - function preConnect(); - - /** - * Connects the mode - * - * @param string $mode - * @return void - */ - function connectTo($mode); - - /** - * Called after all calls to connectTo - * @return void - */ - function postConnect(); - - /** - * Check if given mode is accepted inside this mode - * - * @param string $mode - * @return bool - */ - function accepts($mode); -} - -/** - * 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> - */ -class Doku_Parser_Mode implements Doku_Parser_Mode_Interface { - /** - * @var Doku_Lexer $Lexer - */ - var $Lexer; - var $allowedModes = array(); - - function getSort() { - trigger_error('getSort() not implemented in '.get_class($this), E_USER_WARNING); - } - - function preConnect() {} - function connectTo($mode) {} - function postConnect() {} - function accepts($mode) { - return in_array($mode, (array) $this->allowedModes ); - } -} - -/** - * Basically the same as Doku_Parser_Mode but extends from DokuWiki_Plugin - * - * Adds additional functions to syntax plugins - */ -class Doku_Parser_Mode_Plugin extends DokuWiki_Plugin implements Doku_Parser_Mode_Interface { - /** - * @var Doku_Lexer $Lexer - */ - var $Lexer; - var $allowedModes = array(); - - /** - * Sort for applying this mode - * - * @return int - */ - function getSort() { - trigger_error('getSort() not implemented in '.get_class($this), E_USER_WARNING); - } - - function preConnect() {} - function connectTo($mode) {} - function postConnect() {} - function accepts($mode) { - return in_array($mode, (array) $this->allowedModes ); - } -} - -//------------------------------------------------------------------- -class Doku_Parser_Mode_base extends Doku_Parser_Mode { - - 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'] - ); - } - - function getSort() { - return 0; - } -} - -//------------------------------------------------------------------- -class Doku_Parser_Mode_footnote extends Doku_Parser_Mode { - - 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)]); - } - - function connectTo($mode) { - $this->Lexer->addEntryPattern( - '\x28\x28(?=.*\x29\x29)',$mode,'footnote' - ); - } - - function postConnect() { - $this->Lexer->addExitPattern( - '\x29\x29','footnote' - ); - } - - function getSort() { - return 150; - } -} - -//------------------------------------------------------------------- -class Doku_Parser_Mode_header extends Doku_Parser_Mode { - - 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' - ); - } - - function getSort() { - return 50; - } -} - -//------------------------------------------------------------------- -class Doku_Parser_Mode_notoc extends Doku_Parser_Mode { - - function connectTo($mode) { - $this->Lexer->addSpecialPattern('~~NOTOC~~',$mode,'notoc'); - } - - function getSort() { - return 30; - } -} - -//------------------------------------------------------------------- -class Doku_Parser_Mode_nocache extends Doku_Parser_Mode { - - function connectTo($mode) { - $this->Lexer->addSpecialPattern('~~NOCACHE~~',$mode,'nocache'); - } - - function getSort() { - return 40; - } -} - -//------------------------------------------------------------------- -class Doku_Parser_Mode_linebreak extends Doku_Parser_Mode { - - function connectTo($mode) { - $this->Lexer->addSpecialPattern('\x5C{2}(?:[ \t]|(?=\n))',$mode,'linebreak'); - } - - function getSort() { - return 140; - } -} - -//------------------------------------------------------------------- -class Doku_Parser_Mode_eol extends Doku_Parser_Mode { - - 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'); - } - - function getSort() { - return 370; - } -} - -//------------------------------------------------------------------- -class Doku_Parser_Mode_hr extends Doku_Parser_Mode { - - function connectTo($mode) { - $this->Lexer->addSpecialPattern('\n[ \t]*-{4,}[ \t]*(?=\n)',$mode,'hr'); - } - - function getSort() { - return 160; - } -} - -//------------------------------------------------------------------- -/** - * This class sets the markup for bold (=strong), - * italic (=emphasis), underline etc. - */ -class Doku_Parser_Mode_formatting extends Doku_Parser_Mode { - var $type; - - var $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 - */ - 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'] - ); - } - - 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 - ); - } - - function postConnect() { - - $this->Lexer->addExitPattern( - $this->formatting[$this->type]['exit'], - $this->type - ); - - } - - function getSort() { - return $this->formatting[$this->type]['sort']; - } -} - -//------------------------------------------------------------------- -class Doku_Parser_Mode_listblock extends Doku_Parser_Mode { - - function __construct() { - global $PARSER_MODES; - - $this->allowedModes = array_merge ( - $PARSER_MODES['formatting'], - $PARSER_MODES['substition'], - $PARSER_MODES['disabled'], - $PARSER_MODES['protected'] #XXX new - ); - - // $this->allowedModes[] = 'footnote'; - } - - 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'); - - } - - function postConnect() { - $this->Lexer->addExitPattern('\n','listblock'); - } - - function getSort() { - return 10; - } -} - -//------------------------------------------------------------------- -class Doku_Parser_Mode_table extends Doku_Parser_Mode { - - function __construct() { - global $PARSER_MODES; - - $this->allowedModes = array_merge ( - $PARSER_MODES['formatting'], - $PARSER_MODES['substition'], - $PARSER_MODES['disabled'], - $PARSER_MODES['protected'] - ); - } - - function connectTo($mode) { - $this->Lexer->addEntryPattern('[\t ]*\n\^',$mode,'table'); - $this->Lexer->addEntryPattern('[\t ]*\n\|',$mode,'table'); - } - - 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'); - } - - function getSort() { - return 60; - } -} - -//------------------------------------------------------------------- -class Doku_Parser_Mode_unformatted extends Doku_Parser_Mode { - - function connectTo($mode) { - $this->Lexer->addEntryPattern('<nowiki>(?=.*</nowiki>)',$mode,'unformatted'); - $this->Lexer->addEntryPattern('%%(?=.*%%)',$mode,'unformattedalt'); - } - - function postConnect() { - $this->Lexer->addExitPattern('</nowiki>','unformatted'); - $this->Lexer->addExitPattern('%%','unformattedalt'); - $this->Lexer->mapHandler('unformattedalt','unformatted'); - } - - function getSort() { - return 170; - } -} - -//------------------------------------------------------------------- -class Doku_Parser_Mode_php extends Doku_Parser_Mode { - - function connectTo($mode) { - $this->Lexer->addEntryPattern('<php>(?=.*</php>)',$mode,'php'); - $this->Lexer->addEntryPattern('<PHP>(?=.*</PHP>)',$mode,'phpblock'); - } - - function postConnect() { - $this->Lexer->addExitPattern('</php>','php'); - $this->Lexer->addExitPattern('</PHP>','phpblock'); - } - - function getSort() { - return 180; - } -} - -//------------------------------------------------------------------- -class Doku_Parser_Mode_html extends Doku_Parser_Mode { - - function connectTo($mode) { - $this->Lexer->addEntryPattern('<html>(?=.*</html>)',$mode,'html'); - $this->Lexer->addEntryPattern('<HTML>(?=.*</HTML>)',$mode,'htmlblock'); - } - - function postConnect() { - $this->Lexer->addExitPattern('</html>','html'); - $this->Lexer->addExitPattern('</HTML>','htmlblock'); - } - - function getSort() { - return 190; - } -} - -//------------------------------------------------------------------- -class Doku_Parser_Mode_preformatted extends Doku_Parser_Mode { - - 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'); - - } - - function postConnect() { - $this->Lexer->addExitPattern('\n','preformatted'); - } - - function getSort() { - return 20; - } -} - -//------------------------------------------------------------------- -class Doku_Parser_Mode_code extends Doku_Parser_Mode { - - function connectTo($mode) { - $this->Lexer->addEntryPattern('<code\b(?=.*</code>)',$mode,'code'); - } - - function postConnect() { - $this->Lexer->addExitPattern('</code>','code'); - } - - function getSort() { - return 200; - } -} - -//------------------------------------------------------------------- -class Doku_Parser_Mode_file extends Doku_Parser_Mode { - - function connectTo($mode) { - $this->Lexer->addEntryPattern('<file\b(?=.*</file>)',$mode,'file'); - } - - function postConnect() { - $this->Lexer->addExitPattern('</file>','file'); - } - - function getSort() { - return 210; - } -} - -//------------------------------------------------------------------- -class Doku_Parser_Mode_quote extends Doku_Parser_Mode { - - function __construct() { - global $PARSER_MODES; - - $this->allowedModes = array_merge ( - $PARSER_MODES['formatting'], - $PARSER_MODES['substition'], - $PARSER_MODES['disabled'], - $PARSER_MODES['protected'] #XXX new - ); - #$this->allowedModes[] = 'footnote'; - #$this->allowedModes[] = 'preformatted'; - #$this->allowedModes[] = 'unformatted'; - } - - function connectTo($mode) { - $this->Lexer->addEntryPattern('\n>{1,}',$mode,'quote'); - } - - function postConnect() { - $this->Lexer->addPattern('\n>{1,}','quote'); - $this->Lexer->addExitPattern('\n','quote'); - } - - function getSort() { - return 220; - } -} - -//------------------------------------------------------------------- -class Doku_Parser_Mode_acronym extends Doku_Parser_Mode { - // A list - var $acronyms = array(); - var $pattern = ''; - - function __construct($acronyms) { - usort($acronyms,array($this,'_compare')); - $this->acronyms = $acronyms; - } - - 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.')'; - } - - function connectTo($mode) { - if(!count($this->acronyms)) return; - - if ( strlen($this->pattern) > 0 ) { - $this->Lexer->addSpecialPattern($this->pattern,$mode,'acronym'); - } - } - - function getSort() { - return 240; - } - - /** - * sort callback to order by string length descending - * - * @param string $a - * @param string $b - * - * @return int - */ - function _compare($a,$b) { - $a_len = strlen($a); - $b_len = strlen($b); - if ($a_len > $b_len) { - return -1; - } else if ($a_len < $b_len) { - return 1; - } - - return 0; - } -} - -//------------------------------------------------------------------- -class Doku_Parser_Mode_smiley extends Doku_Parser_Mode { - // A list - var $smileys = array(); - var $pattern = ''; - - function __construct($smileys) { - $this->smileys = $smileys; - } - - 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 = '|'; - } - } - - function connectTo($mode) { - if(!count($this->smileys)) return; - - if ( strlen($this->pattern) > 0 ) { - $this->Lexer->addSpecialPattern($this->pattern,$mode,'smiley'); - } - } - - function getSort() { - return 230; - } -} - -//------------------------------------------------------------------- -class Doku_Parser_Mode_wordblock extends Doku_Parser_Mode { - // A list - var $badwords = array(); - var $pattern = ''; - - function __construct($badwords) { - $this->badwords = $badwords; - } - - 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 = '|'; - } - - } - - function connectTo($mode) { - if ( strlen($this->pattern) > 0 ) { - $this->Lexer->addSpecialPattern($this->pattern,$mode,'wordblock'); - } - } - - function getSort() { - return 250; - } -} - -//------------------------------------------------------------------- -class Doku_Parser_Mode_entity extends Doku_Parser_Mode { - // A list - var $entities = array(); - var $pattern = ''; - - function __construct($entities) { - $this->entities = $entities; - } - - function preConnect() { - if(!count($this->entities) || $this->pattern != '') return; - - $sep = ''; - foreach ( $this->entities as $entity ) { - $this->pattern .= $sep.Doku_Lexer_Escape($entity); - $sep = '|'; - } - } - - function connectTo($mode) { - if(!count($this->entities)) return; - - if ( strlen($this->pattern) > 0 ) { - $this->Lexer->addSpecialPattern($this->pattern,$mode,'entity'); - } - } - - function getSort() { - return 260; - } -} - -//------------------------------------------------------------------- -// Implements the 640x480 replacement -class Doku_Parser_Mode_multiplyentity extends Doku_Parser_Mode { - - function connectTo($mode) { - - $this->Lexer->addSpecialPattern( - '(?<=\b)(?:[1-9]|\d{2,})[xX]\d+(?=\b)',$mode,'multiplyentity' - ); - - } - - function getSort() { - return 270; - } -} - -//------------------------------------------------------------------- -class Doku_Parser_Mode_quotes extends Doku_Parser_Mode { - - 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' - ); - - } - - function getSort() { - return 280; - } -} - -//------------------------------------------------------------------- -class Doku_Parser_Mode_camelcaselink extends Doku_Parser_Mode { - - function connectTo($mode) { - $this->Lexer->addSpecialPattern( - '\b[A-Z]+[a-z]+[A-Z][A-Za-z]*\b',$mode,'camelcaselink' - ); - } - - function getSort() { - return 290; - } -} - -//------------------------------------------------------------------- -class Doku_Parser_Mode_internallink extends Doku_Parser_Mode { - - function connectTo($mode) { - // Word boundaries? - $this->Lexer->addSpecialPattern("\[\[.*?\]\](?!\])",$mode,'internallink'); - } - - function getSort() { - return 300; - } -} - -//------------------------------------------------------------------- -class Doku_Parser_Mode_media extends Doku_Parser_Mode { - - function connectTo($mode) { - // Word boundaries? - $this->Lexer->addSpecialPattern("\{\{(?:[^\}]|(?:\}[^\}]))+\}\}",$mode,'media'); - } - - function getSort() { - return 320; - } -} - -//------------------------------------------------------------------- -class Doku_Parser_Mode_rss extends Doku_Parser_Mode { - - function connectTo($mode) { - $this->Lexer->addSpecialPattern("\{\{rss>[^\}]+\}\}",$mode,'rss'); - } - - function getSort() { - return 310; - } -} - -//------------------------------------------------------------------- -class Doku_Parser_Mode_externallink extends Doku_Parser_Mode { - var $schemes = array(); - var $patterns = array(); - - 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.'])'; - } - - function connectTo($mode) { - - foreach ( $this->patterns as $pattern ) { - $this->Lexer->addSpecialPattern($pattern,$mode,'externallink'); - } - } - - function getSort() { - return 330; - } -} - -//------------------------------------------------------------------- -class Doku_Parser_Mode_filelink extends Doku_Parser_Mode { - - var $pattern; - - function preConnect() { - - $ltrs = '\w'; - $gunk = '/\#~:.?+=&%@!\-'; - $punc = '.:?\-;,'; - $host = $ltrs.$punc; - $any = $ltrs.$gunk.$punc; - - $this->pattern = '\b(?i)file(?-i)://['.$any.']+?['. - $punc.']*[^'.$any.']'; - } - - function connectTo($mode) { - $this->Lexer->addSpecialPattern( - $this->pattern,$mode,'filelink'); - } - - function getSort() { - return 360; - } -} - -//------------------------------------------------------------------- -class Doku_Parser_Mode_windowssharelink extends Doku_Parser_Mode { - - var $pattern; - - function preConnect() { - $this->pattern = "\\\\\\\\\w+?(?:\\\\[\w\-$]+)+"; - } - - function connectTo($mode) { - $this->Lexer->addSpecialPattern( - $this->pattern,$mode,'windowssharelink'); - } - - function getSort() { - return 350; - } -} - -//------------------------------------------------------------------- -class Doku_Parser_Mode_emaillink extends Doku_Parser_Mode { - - function connectTo($mode) { - // pattern below is defined in inc/mail.php - $this->Lexer->addSpecialPattern('<'.PREG_PATTERN_VALID_EMAIL.'>',$mode,'emaillink'); - } - - function getSort() { - return 340; - } -} - //Setup VIM: ex: et ts=4 : diff --git a/inc/parserutils.php b/inc/parserutils.php index 1b8a58983..965e92234 100644 --- a/inc/parserutils.php +++ b/inc/parserutils.php @@ -569,7 +569,7 @@ function p_get_parsermodes(){ $std_modes[] = 'multiplyentity'; } foreach($std_modes as $m){ - $class = "Doku_Parser_Mode_$m"; + $class = 'dokuwiki\\ParserMode\\'.ucfirst($m); $obj = new $class(); $modes[] = array( 'sort' => $obj->getSort(), @@ -582,7 +582,7 @@ function p_get_parsermodes(){ $fmt_modes = array('strong','emphasis','underline','monospace', 'subscript','superscript','deleted'); foreach($fmt_modes as $m){ - $obj = new Doku_Parser_Mode_formatting($m); + $obj = new \dokuwiki\ParserMode\Formatting($m); $modes[] = array( 'sort' => $obj->getSort(), 'mode' => $m, @@ -591,16 +591,16 @@ function p_get_parsermodes(){ } // add modes which need files - $obj = new Doku_Parser_Mode_smiley(array_keys(getSmileys())); + $obj = new \dokuwiki\ParserMode\Smiley(array_keys(getSmileys())); $modes[] = array('sort' => $obj->getSort(), 'mode' => 'smiley','obj' => $obj ); - $obj = new Doku_Parser_Mode_acronym(array_keys(getAcronyms())); + $obj = new \dokuwiki\ParserMode\Acronym(array_keys(getAcronyms())); $modes[] = array('sort' => $obj->getSort(), 'mode' => 'acronym','obj' => $obj ); - $obj = new Doku_Parser_Mode_entity(array_keys(getEntities())); + $obj = new \dokuwiki\ParserMode\Entity(array_keys(getEntities())); $modes[] = array('sort' => $obj->getSort(), 'mode' => 'entity','obj' => $obj ); // add optional camelcase mode if($conf['camelcase']){ - $obj = new Doku_Parser_Mode_camelcaselink(); + $obj = new \dokuwiki\ParserMode\Camelcaselink(); $modes[] = array('sort' => $obj->getSort(), 'mode' => 'camelcaselink','obj' => $obj ); } diff --git a/lib/plugins/syntax.php b/lib/plugins/syntax.php index 133a64535..0d9ad814b 100644 --- a/lib/plugins/syntax.php +++ b/lib/plugins/syntax.php @@ -8,7 +8,8 @@ * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Andreas Gohr <andi@splitbrain.org> */ -abstract class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode_Plugin { +abstract class DokuWiki_Syntax_Plugin extends \dokuwiki\ParserMode\Plugin { + use DokuWiki_PluginTrait; protected $allowedModesSetup = false; |