Skip to content

Commit

Permalink
Use no-break narrow space for most French punctuation, use full no-br…
Browse files Browse the repository at this point in the history
…eak space for colon. Fixes #36.
  • Loading branch information
mundschenk-at committed May 29, 2016
1 parent 09f6743 commit 68358e6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions php-typography/class-php-typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -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?)((?<!&amp|&gt|&lt);)(\s|\Z)/u';
$this->regex['frenchPunctuationSpacingOpeningQuote'] = '/(\s|\A)(«)(\s?)(\w+)/u';

Expand Down Expand Up @@ -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 );
}
Expand Down
6 changes: 3 additions & 3 deletions tests/class-php-typography-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2151,12 +2151,12 @@ public function provide_french_punctuation_spacing_data() {
array( "Je t'aime; m'aimes-tu?", "Je t'aime&#8239;; m'aimes-tu&#8239;?" ),
array( 'Au secours !', 'Au secours&#8239;!' ),
array( 'Au secours!', 'Au secours&#8239;!' ),
array( 'Jean a dit : Foo', 'Jean a dit&#8239;: Foo' ),
array( 'Jean a dit: Foo', 'Jean a dit&#8239;: Foo' ),
array( 'Jean a dit : Foo', 'Jean a dit&nbsp;: Foo' ),
array( 'Jean a dit: Foo', 'Jean a dit&nbsp;: Foo' ),
array( 'http://example.org', 'http://example.org' ),
array( 'foo &Ouml; & ; bar', 'foo &Ouml; &amp; ; bar' ),
array( '5 > 3', '5 > 3' ),
array( 'Les « courants de bord ouest » du Pacifique ? Eh bien : ils sont "fabuleux".', 'Les &laquo;&#8239;courants de bord ouest&#8239;&raquo; du Pacifique&#8239;? Eh bien&#8239;: ils sont "fabuleux".' ),
array( 'Les « courants de bord ouest » du Pacifique ? Eh bien : ils sont "fabuleux".', 'Les &laquo;&#8239;courants de bord ouest&#8239;&raquo; du Pacifique&#8239;? Eh bien&nbsp;: ils sont "fabuleux".' ),

);
}
Expand Down

0 comments on commit 68358e6

Please sign in to comment.