diff options
author | Andreas Gohr <andi@splitbrain.org> | 2007-05-13 10:40:24 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2007-05-13 10:40:24 +0200 |
commit | 57d757d195f73c836bb15fc1cd1d01fa0dcc75b1 (patch) | |
tree | 352ac377c2f568e7e9e1229d81733a95011d753c | |
parent | d613051ae9b5db0528293dbe6d918df6dbd7dc4e (diff) | |
download | rpg-57d757d195f73c836bb15fc1cd1d01fa0dcc75b1.tar.gz rpg-57d757d195f73c836bb15fc1cd1d01fa0dcc75b1.tar.bz2 |
distinction between apostrophes and single quotes FS#1127
This patch adds another parser mode for apostrophes. Now single quote closing
markers are handled different from apostrophes for better local typograpy
support.
Needs testing and languages updates.
darcs-hash:20070513084024-7ad00-d20fe093a093c265d357b178e199c1596b484996.gz
-rw-r--r-- | _test/cases/inc/parser/parser_quotes.test.php | 267 | ||||
-rw-r--r-- | _test/cases/inc/parser/parser_replacements.test.php | 196 | ||||
-rw-r--r-- | inc/lang/en/lang.php | 1 | ||||
-rw-r--r-- | inc/parser/handler.php | 5 | ||||
-rw-r--r-- | inc/parser/metadata.php | 5 | ||||
-rw-r--r-- | inc/parser/parser.php | 14 | ||||
-rw-r--r-- | inc/parser/renderer.php | 2 | ||||
-rw-r--r-- | inc/parser/xhtml.php | 5 |
8 files changed, 340 insertions, 155 deletions
diff --git a/_test/cases/inc/parser/parser_quotes.test.php b/_test/cases/inc/parser/parser_quotes.test.php new file mode 100644 index 000000000..90616424f --- /dev/null +++ b/_test/cases/inc/parser/parser_quotes.test.php @@ -0,0 +1,267 @@ +<?php +require_once 'parser.inc.php'; + +class TestOfDoku_Parser_Quotes extends TestOfDoku_Parser { + + function TestOfDoku_Parser_Quotes() { + $this->UnitTestCase('TestOfDoku_Parser_Quotes'); + } + + function testSingleQuoteOpening() { + $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->parse("Foo 'hello Bar"); + + $calls = array ( + array('document_start',array()), + array('p_open',array()), + array('cdata',array("\n".'Foo ')), + array('singlequoteopening',array()), + array('cdata',array('hello Bar'."\n")), + array('p_close',array()), + array('document_end',array()), + ); + + $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); + } + + function testSingleQuoteOpeningSpecial() { + $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->parse("Foo said:'hello Bar"); + + $calls = array ( + array('document_start',array()), + array('p_open',array()), + array('cdata',array("\n".'Foo said:')), + array('singlequoteopening',array()), + array('cdata',array('hello Bar'."\n")), + array('p_close',array()), + array('document_end',array()), + ); + + $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); + } + + function testSingleQuoteClosing() { + $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->parse("Foo hello' Bar"); + + $calls = array ( + array('document_start',array()), + array('p_open',array()), + array('cdata',array("\n".'Foo hello')), + array('singlequoteclosing',array()), + array('cdata',array(' Bar'."\n")), + array('p_close',array()), + array('document_end',array()), + ); + + $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); + } + + function testSingleQuoteClosingSpecial() { + $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->parse("Foo hello') Bar"); + + $calls = array ( + array('document_start',array()), + array('p_open',array()), + array('cdata',array("\n".'Foo hello')), + array('singlequoteclosing',array()), + array('cdata',array(') Bar'."\n")), + array('p_close',array()), + array('document_end',array()), + ); + + $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); + } + + function testSingleQuotes() { + $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->parse("Foo 'hello' Bar"); + + $calls = array ( + array('document_start',array()), + array('p_open',array()), + array('cdata',array("\n".'Foo ')), + array('singlequoteopening',array()), + array('cdata',array('hello')), + array('singlequoteclosing',array()), + array('cdata',array(' Bar'."\n")), + array('p_close',array()), + array('document_end',array()), + ); + + $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); + } + + function testApostrophe() { + $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->parse("hey it's fine weather today"); + + $calls = array ( + array('document_start',array()), + array('p_open',array()), + array('cdata',array("\n".'hey it')), + array('apostrophe',array()), + array('cdata',array('s fine weather today'."\n")), + array('p_close',array()), + array('document_end',array()), + ); + + $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); + } + + + function testSingleQuotesSpecial() { + $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->parse("Foo ('hello') Bar"); + + $calls = array ( + array('document_start',array()), + array('p_open',array()), + array('cdata',array("\n".'Foo (')), + array('singlequoteopening',array()), + array('cdata',array('hello')), + array('singlequoteclosing',array()), + array('cdata',array(') Bar'."\n")), + array('p_close',array()), + array('document_end',array()), + ); + + $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); + } + + function testDoubleQuoteOpening() { + $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->parse('Foo "hello Bar'); + + $calls = array ( + array('document_start',array()), + array('p_open',array()), + array('cdata',array("\n".'Foo ')), + array('doublequoteopening',array()), + array('cdata',array('hello Bar'."\n")), + array('p_close',array()), + array('document_end',array()), + ); + + $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); + } + + function testDoubleQuoteOpeningSpecial() { + $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->parse('Foo said:"hello Bar'); + + $calls = array ( + array('document_start',array()), + array('p_open',array()), + array('cdata',array("\n".'Foo said:')), + array('doublequoteopening',array()), + array('cdata',array('hello Bar'."\n")), + array('p_close',array()), + array('document_end',array()), + ); + + $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); + } + + function testDoubleQuoteClosing() { + $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->parse('Foo hello" Bar'); + + $calls = array ( + array('document_start',array()), + array('p_open',array()), + array('cdata',array("\n".'Foo hello')), + array('doublequoteclosing',array()), + array('cdata',array(' Bar'."\n")), + array('p_close',array()), + array('document_end',array()), + ); + + $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); + } + + function testDoubleQuoteClosingSpecial() { + $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->parse('Foo hello") Bar'); + + $calls = array ( + array('document_start',array()), + array('p_open',array()), + array('cdata',array("\n".'Foo hello')), + array('doublequoteclosing',array()), + array('cdata',array(') Bar'."\n")), + array('p_close',array()), + array('document_end',array()), + ); + + $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); + } + + function testDoubleQuotes() { + $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->parse('Foo "hello" Bar'); + + $calls = array ( + array('document_start',array()), + array('p_open',array()), + array('cdata',array("\n".'Foo ')), + array('doublequoteopening',array()), + array('cdata',array('hello')), + array('doublequoteclosing',array()), + array('cdata',array(' Bar'."\n")), + array('p_close',array()), + array('document_end',array()), + ); + + $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); + } + + function testDoubleQuotesSpecial() { + $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->parse('Foo ("hello") Bar'); + + $calls = array ( + array('document_start',array()), + array('p_open',array()), + array('cdata',array("\n".'Foo (')), + array('doublequoteopening',array()), + array('cdata',array('hello')), + array('doublequoteclosing',array()), + array('cdata',array(') Bar'."\n")), + array('p_close',array()), + array('document_end',array()), + ); + + $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); + } + + function testAllQuotes() { + $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); + $this->P->parse('There was written "He thought \'It\'s a man\'s world\'".'); + + $calls = array ( + array('document_start',array()), + array('p_open',array()), + array('cdata',array("\n".'There was written ')), + array('doublequoteopening',array()), + array('cdata',array('He thought ')), + array('singlequoteopening',array()), + array('cdata',array('It')), + array('apostrophe',array()), + array('cdata',array('s a man')), + array('apostrophe',array()), + array('cdata',array('s world')), + array('singlequoteclosing',array()), + array('doublequoteclosing',array()), + array('cdata',array('.'."\n")), + array('p_close',array()), + array('document_end',array()), + ); + + $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); + } + +} + diff --git a/_test/cases/inc/parser/parser_replacements.test.php b/_test/cases/inc/parser/parser_replacements.test.php index 50de0dc17..efd20f397 100644 --- a/_test/cases/inc/parser/parser_replacements.test.php +++ b/_test/cases/inc/parser/parser_replacements.test.php @@ -2,16 +2,16 @@ require_once 'parser.inc.php'; class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { - + function TestOfDoku_Parser_Replacements() { $this->UnitTestCase('TestOfDoku_Parser_Replacements'); } - - + + function testSingleAcronym() { $this->P->addMode('acronym',new Doku_Parser_Mode_Acronym(array('FOOBAR'))); $this->P->parse('abc FOOBAR xyz'); - + $calls = array ( array('document_start',array()), array('p_open',array()), @@ -21,14 +21,14 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { array('p_close',array()), array('document_end',array()), ); - + $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); } - + function testAlmostAnAcronym() { $this->P->addMode('acronym',new Doku_Parser_Mode_Acronym(array('FOOBAR'))); $this->P->parse('abcFOOBARxyz'); - + $calls = array ( array('document_start',array()), array('p_open',array()), @@ -36,14 +36,14 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { array('p_close',array()), array('document_end',array()), ); - + $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); } - + function testMultipleAcronyms() { $this->P->addMode('acronym',new Doku_Parser_Mode_Acronym(array('FOO','BAR'))); $this->P->parse('abc FOO def BAR xyz'); - + $calls = array ( array('document_start',array()), array('p_open',array()), @@ -55,16 +55,16 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { array('p_close',array()), array('document_end',array()), ); - + $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); - + } - // - + // + function testSingleSmiley() { $this->P->addMode('smiley',new Doku_Parser_Mode_Smiley(array(':-)'))); $this->P->parse('abc:-)xyz'); - + $calls = array ( array('document_start',array()), array('p_open',array()), @@ -74,14 +74,14 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { array('p_close',array()), array('document_end',array()), ); - + $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); } - + function testMultipleSmileys() { $this->P->addMode('smiley',new Doku_Parser_Mode_Smiley(array(':-)','^_^'))); $this->P->parse('abc:-)x^_^yz'); - + $calls = array ( array('document_start',array()), array('p_open',array()), @@ -93,16 +93,16 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { array('p_close',array()), array('document_end',array()), ); - + $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); - + } - + function testBackslashSmiley() { // This smiley is really :-\\ but escaping makes like interesting $this->P->addMode('smiley',new Doku_Parser_Mode_Smiley(array(':-\\\\'))); $this->P->parse('abc:-\\\xyz'); - + $calls = array ( array('document_start',array()), array('p_open',array()), @@ -112,14 +112,14 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { array('p_close',array()), array('document_end',array()), ); - + $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); } - + function testSingleWordblock() { $this->P->addMode('wordblock',new Doku_Parser_Mode_Wordblock(array('CAT'))); $this->P->parse('abc CAT xyz'); - + $calls = array ( array('document_start',array()), array('p_open',array()), @@ -129,14 +129,14 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { array('p_close',array()), array('document_end',array()), ); - + $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); } - + function testWordblockCase() { $this->P->addMode('wordblock',new Doku_Parser_Mode_Wordblock(array('CAT'))); $this->P->parse('abc cat xyz'); - + $calls = array ( array('document_start',array()), array('p_open',array()), @@ -146,14 +146,14 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { array('p_close',array()), array('document_end',array()), ); - + $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); } - + function testMultipleWordblock() { $this->P->addMode('wordblock',new Doku_Parser_Mode_Wordblock(array('CAT','dog'))); $this->P->parse('abc cat x DOG yz'); - + $calls = array ( array('document_start',array()), array('p_open',array()), @@ -165,14 +165,14 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { array('p_close',array()), array('document_end',array()), ); - + $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); } - + function testSingleEntity() { $this->P->addMode('entity',new Doku_Parser_Mode_Entity(array('->'))); $this->P->parse('x -> y'); - + $calls = array ( array('document_start',array()), array('p_open',array()), @@ -182,14 +182,14 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { array('p_close',array()), array('document_end',array()), ); - + $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); } - + function testMultipleEntities() { $this->P->addMode('entity',new Doku_Parser_Mode_Entity(array('->','<-'))); $this->P->parse('x -> y <- z'); - + $calls = array ( array('document_start',array()), array('p_open',array()), @@ -201,14 +201,14 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { array('p_close',array()), array('document_end',array()), ); - + $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); } - + function testMultiplyEntity() { $this->P->addMode('multiplyentity',new Doku_Parser_Mode_MultiplyEntity()); $this->P->parse('Foo 10x20 Bar'); - + $calls = array ( array('document_start',array()), array('p_open',array()), @@ -218,120 +218,14 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { array('p_close',array()), array('document_end',array()), ); - - $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); - } - - function testSingleQuoteOpening() { - $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); - $this->P->parse("Foo 'hello Bar"); - - $calls = array ( - array('document_start',array()), - array('p_open',array()), - array('cdata',array("\n".'Foo ')), - array('singlequoteopening',array()), - array('cdata',array('hello Bar'."\n")), - array('p_close',array()), - array('document_end',array()), - ); - - $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); - } - - function testSingleQuoteClosing() { - $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); - $this->P->parse("Foo hello' Bar"); - - $calls = array ( - array('document_start',array()), - array('p_open',array()), - array('cdata',array("\n".'Foo hello')), - array('singlequoteclosing',array()), - array('cdata',array(' Bar'."\n")), - array('p_close',array()), - array('document_end',array()), - ); - - $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); - } - - function testSingleQuotes() { - $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); - $this->P->parse("Foo 'hello' Bar"); - - $calls = array ( - array('document_start',array()), - array('p_open',array()), - array('cdata',array("\n".'Foo ')), - array('singlequoteopening',array()), - array('cdata',array('hello')), - array('singlequoteclosing',array()), - array('cdata',array(' Bar'."\n")), - array('p_close',array()), - array('document_end',array()), - ); - - $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); - } - - function testDoubleQuoteOpening() { - $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); - $this->P->parse('Foo "hello Bar'); - - $calls = array ( - array('document_start',array()), - array('p_open',array()), - array('cdata',array("\n".'Foo ')), - array('doublequoteopening',array()), - array('cdata',array('hello Bar'."\n")), - array('p_close',array()), - array('document_end',array()), - ); - - $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); - } - - function testDoubleQuoteClosing() { - $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); - $this->P->parse('Foo hello" Bar'); - - $calls = array ( - array('document_start',array()), - array('p_open',array()), - array('cdata',array("\n".'Foo hello')), - array('doublequoteclosing',array()), - array('cdata',array(' Bar'."\n")), - array('p_close',array()), - array('document_end',array()), - ); - - $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); - } - - function testDoubleQuotes() { - $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes()); - $this->P->parse('Foo "hello" Bar'); - - $calls = array ( - array('document_start',array()), - array('p_open',array()), - array('cdata',array("\n".'Foo ')), - array('doublequoteopening',array()), - array('cdata',array('hello')), - array('doublequoteclosing',array()), - array('cdata',array(' Bar'."\n")), - array('p_close',array()), - array('document_end',array()), - ); - + $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); } - + function testHR() { $this->P->addMode('hr',new Doku_Parser_Mode_HR()); $this->P->parse("Foo \n ---- \n Bar"); - + $calls = array ( array('document_start',array()), array('p_open',array()), @@ -345,11 +239,11 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls); } - + function testHREol() { $this->P->addMode('hr',new Doku_Parser_Mode_HR()); $this->P->parse("Foo \n----\n Bar"); - + $calls = array ( array('document_start',array()), array('p_open',array()), diff --git a/inc/lang/en/lang.php b/inc/lang/en/lang.php index 23f17c52c..718efa03b 100644 --- a/inc/lang/en/lang.php +++ b/inc/lang/en/lang.php @@ -13,6 +13,7 @@ $lang['doublequoteopening'] = '“';//“ $lang['doublequoteclosing'] = '”';//” $lang['singlequoteopening'] = '‘';//‘ $lang['singlequoteclosing'] = '’';//’ +$lang['apostrophe'] = '’';//’ $lang['btn_edit'] = 'Edit this page'; $lang['btn_source'] = 'Show pagesource'; diff --git a/inc/parser/handler.php b/inc/parser/handler.php index d8e6c79ea..0a021987f 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -407,6 +407,11 @@ class Doku_Handler { return true; } + function apostrophe($match, $state, $pos) { + $this->_addCall('apostrophe',array(), $pos); + return true; + } + function doublequoteopening($match, $state, $pos) { $this->_addCall('doublequoteopening',array(), $pos); return true; diff --git a/inc/parser/metadata.php b/inc/parser/metadata.php index 85e6eefed..846bbff23 100644 --- a/inc/parser/metadata.php +++ b/inc/parser/metadata.php @@ -255,6 +255,11 @@ class Doku_Renderer_metadata extends Doku_Renderer { if ($this->capture) $this->doc .= $lang['singlequoteclosing']; } + function apostrophe() { + global $lang; + $this->doc .= $lang['apostrophe']; + } + function doublequoteopening(){ global $lang; if ($this->capture) $this->doc .= $lang['doublequoteopening']; diff --git a/inc/parser/parser.php b/inc/parser/parser.php index 0d88580d2..577e1137c 100644 --- a/inc/parser/parser.php +++ b/inc/parser/parser.php @@ -758,19 +758,25 @@ class Doku_Parser_Mode_multiplyentity extends Doku_Parser_Mode { class Doku_Parser_Mode_quotes extends Doku_Parser_Mode { function connectTo($mode) { + $ws = '[\s/\#~:\.?+=&%@!\-;,\x28\x29\]\[{}><"\']'; // whitespace + $nws = '[^\s/\#~:\.?+=&%@!\-;,\x28\x29\]\[{}><"\']'; // non whitespace $this->Lexer->addSpecialPattern( - '(?<=^|\s)\'(?=\S)',$mode,'singlequoteopening' + "(?<=^|$ws)'(?=$nws)",$mode,'singlequoteopening' ); $this->Lexer->addSpecialPattern( - '(?<=^|\S)\'',$mode,'singlequoteclosing' + "(?<=^|$nws)'(?=$|$ws)",$mode,'singlequoteclosing' ); $this->Lexer->addSpecialPattern( - '(?<=^|\s)"(?=\S)',$mode,'doublequoteopening' + "(?<=^|$nws)'(?=$|$nws)",$mode,'apostrophe' ); $this->Lexer->addSpecialPattern( - '(?<=^|\S)"',$mode,'doublequoteclosing' + "(?<=^|$ws)\"(?=$nws)",$mode,'doublequoteopening' ); + $this->Lexer->addSpecialPattern( + "(?<=^|$nws)\"",$mode,'doublequoteclosing' + ); + } diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php index 1b6340445..808261ddf 100644 --- a/inc/parser/renderer.php +++ b/inc/parser/renderer.php @@ -177,6 +177,8 @@ class Doku_Renderer extends DokuWiki_Plugin { function singlequoteclosing() {} + function apostrophe() {} + function doublequoteopening() {} function doublequoteclosing() {} diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index fad6f6120..438410651 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -455,6 +455,11 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $this->doc .= $lang['singlequoteclosing']; } + function apostrophe() { + global $lang; + $this->doc .= $lang['singlequoteclosing']; + } + function doublequoteopening() { global $lang; $this->doc .= $lang['doublequoteopening']; |