From 68358e6a622b75130514df0b2a7ea740fab8809c Mon Sep 17 00:00:00 2001 From: Der Mundschenk & Compagnie Date: Sun, 29 May 2016 22:56:53 +0200 Subject: [PATCH] Use no-break narrow space for most French punctuation, use full no-break space for colon. Fixes #36. --- php-typography/class-php-typography.php | 6 ++++-- tests/class-php-typography-test.php | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/php-typography/class-php-typography.php b/php-typography/class-php-typography.php index f25cd4b6..844aa832 100644 --- a/php-typography/class-php-typography.php +++ b/php-typography/class-php-typography.php @@ -1089,7 +1089,8 @@ private function initialize_patterns() { $this->update_unit_pattern( isset( $this->settings['units'] ) ? $this->settings['units'] : array() ); // french punctuation spacing - $this->regex['frenchPunctuationSpacing'] = '/(\w+)(\s?)([?!:»])(\s|\Z)/u'; + $this->regex['frenchPunctuationSpacingNarrow'] = '/(\w+)(\s?)([?!»])(\s|\Z)/u'; + $this->regex['frenchPunctuationSpacingFull'] = '/(\w+)(\s?)(:)(\s|\Z)/u'; $this->regex['frenchPunctuationSpacingSemicolon'] = '/(\w+)(\s?)((?regex['frenchPunctuationSpacingOpeningQuote'] = '/(\s|\A)(«)(\s?)(\w+)/u'; @@ -2701,7 +2702,8 @@ function french_punctuation_spacing( \DOMText $textnode ) { return; } - $textnode->data = preg_replace( $this->regex['frenchPunctuationSpacing'], '$1' . $this->chr['noBreakNarrowSpace'] . '$3$4', $textnode->data ); + $textnode->data = preg_replace( $this->regex['frenchPunctuationSpacingNarrow'], '$1' . $this->chr['noBreakNarrowSpace'] . '$3$4', $textnode->data ); + $textnode->data = preg_replace( $this->regex['frenchPunctuationSpacingFull'], '$1' . $this->chr['noBreakSpace'] . '$3$4', $textnode->data ); $textnode->data = preg_replace( $this->regex['frenchPunctuationSpacingSemicolon'], '$1' . $this->chr['noBreakNarrowSpace'] . '$3$4', $textnode->data ); $textnode->data = preg_replace( $this->regex['frenchPunctuationSpacingOpeningQuote'], '$1$2' . $this->chr['noBreakNarrowSpace'] . '$4', $textnode->data ); } diff --git a/tests/class-php-typography-test.php b/tests/class-php-typography-test.php index e62b9600..42b349da 100644 --- a/tests/class-php-typography-test.php +++ b/tests/class-php-typography-test.php @@ -2151,12 +2151,12 @@ public function provide_french_punctuation_spacing_data() { array( "Je t'aime; m'aimes-tu?", "Je t'aime ; m'aimes-tu ?" ), array( 'Au secours !', 'Au secours !' ), array( 'Au secours!', 'Au secours !' ), - array( 'Jean a dit : Foo', 'Jean a dit : Foo' ), - array( 'Jean a dit: Foo', 'Jean a dit : Foo' ), + array( 'Jean a dit : Foo', 'Jean a dit : Foo' ), + array( 'Jean a dit: Foo', 'Jean a dit : Foo' ), array( 'http://example.org', 'http://example.org' ), array( 'foo Ö & ; bar', 'foo Ö & ; bar' ), array( '5 > 3', '5 > 3' ), - array( 'Les « courants de bord ouest » du Pacifique ? Eh bien : ils sont "fabuleux".', 'Les « courants de bord ouest » du Pacifique ? Eh bien : ils sont "fabuleux".' ), + array( 'Les « courants de bord ouest » du Pacifique ? Eh bien : ils sont "fabuleux".', 'Les « courants de bord ouest » du Pacifique ? Eh bien : ils sont "fabuleux".' ), ); }