|
|
@@ -81,13 +81,6 @@ class TypographyHelper extends Helper {
|
|
|
];
|
|
|
|
|
|
/**
|
|
|
- * Cache definitions.
|
|
|
- *
|
|
|
- * @var array|null
|
|
|
- */
|
|
|
- protected $table;
|
|
|
-
|
|
|
- /**
|
|
|
* Automatically uses the typography specified.
|
|
|
* By default, uses Configure::read('App.language') to determine locale preference.
|
|
|
* It will then try to match the language to the type of characters used.
|
|
|
@@ -307,57 +300,55 @@ class TypographyHelper extends Helper {
|
|
|
],
|
|
|
];
|
|
|
|
|
|
- if (!isset($this->table)) {
|
|
|
- $this->table = [
|
|
|
- // nested smart quotes, opening and closing
|
|
|
- // note that rules for grammar (English) allow only for two levels deep
|
|
|
- // and that single quotes are _supposed_ to always be on the outside
|
|
|
- // but we'll accommodate both
|
|
|
- // Note that in all cases, whitespace is the primary determining factor
|
|
|
- // on which direction to curl, with non-word characters like punctuation
|
|
|
- // being a secondary factor only after whitespace is addressed.
|
|
|
- '/\'"(\s|$)/' => '’”$1',
|
|
|
- '/(^|\s|<p>)\'"/' => '$1‘“',
|
|
|
- '/\'"(\W)/' => '’”$1',
|
|
|
- '/(\W)\'"/' => '$1‘“',
|
|
|
- '/"\'(\s|$)/' => '”’$1',
|
|
|
- '/(^|\s|<p>)"\'/' => '$1“‘',
|
|
|
- '/"\'(\W)/' => '”’$1',
|
|
|
- '/(\W)"\'/' => '$1“‘',
|
|
|
-
|
|
|
- // single quote smart quotes
|
|
|
- '/\'(\s|$)/' => '’$1',
|
|
|
- '/(^|\s|<p>)\'/' => '$1‘',
|
|
|
- '/\'(\W)/' => '’$1',
|
|
|
- '/(\W)\'/' => '$1‘',
|
|
|
-
|
|
|
- // double quote smart quotes
|
|
|
- '/"(\s|$)/' => '”$1',
|
|
|
- '/(^|\s|<p>)"/' => '$1“',
|
|
|
- '/"(\W)/' => '”$1',
|
|
|
- '/(\W)"/' => '$1“',
|
|
|
-
|
|
|
- // apostrophes
|
|
|
- "/(\w)'(\w)/" => '$1’$2', // we dont use #8217; to avoid collision on replace
|
|
|
-
|
|
|
- // Em dash and ellipses dots
|
|
|
- '/\s?\-\-\s?/' => '—',
|
|
|
- '/(\w)\.{3}/' => '$1…',
|
|
|
-
|
|
|
- // double space after sentences
|
|
|
- '/(\W) /' => '$1 ',
|
|
|
-
|
|
|
- // ampersands, if not a character entity
|
|
|
- '/&(?!#?[a-zA-Z0-9]{2,};)/' => '&'
|
|
|
- ];
|
|
|
- if ($locale && !empty($locales[$locale])) {
|
|
|
- foreach ($this->table as $key => $val) {
|
|
|
- $this->table[$key] = str_replace($locales['default'], $locales[$locale], $val);
|
|
|
- }
|
|
|
+ $table = [
|
|
|
+ // nested smart quotes, opening and closing
|
|
|
+ // note that rules for grammar (English) allow only for two levels deep
|
|
|
+ // and that single quotes are _supposed_ to always be on the outside
|
|
|
+ // but we'll accommodate both
|
|
|
+ // Note that in all cases, whitespace is the primary determining factor
|
|
|
+ // on which direction to curl, with non-word characters like punctuation
|
|
|
+ // being a secondary factor only after whitespace is addressed.
|
|
|
+ '/\'"(\s|$)/' => '’”$1',
|
|
|
+ '/(^|\s|<p>)\'"/' => '$1‘“',
|
|
|
+ '/\'"(\W)/' => '’”$1',
|
|
|
+ '/(\W)\'"/' => '$1‘“',
|
|
|
+ '/"\'(\s|$)/' => '”’$1',
|
|
|
+ '/(^|\s|<p>)"\'/' => '$1“‘',
|
|
|
+ '/"\'(\W)/' => '”’$1',
|
|
|
+ '/(\W)"\'/' => '$1“‘',
|
|
|
+
|
|
|
+ // single quote smart quotes
|
|
|
+ '/\'(\s|$)/' => '’$1',
|
|
|
+ '/(^|\s|<p>)\'/' => '$1‘',
|
|
|
+ '/\'(\W)/' => '’$1',
|
|
|
+ '/(\W)\'/' => '$1‘',
|
|
|
+
|
|
|
+ // double quote smart quotes
|
|
|
+ '/"(\s|$)/' => '”$1',
|
|
|
+ '/(^|\s|<p>)"/' => '$1“',
|
|
|
+ '/"(\W)/' => '”$1',
|
|
|
+ '/(\W)"/' => '$1“',
|
|
|
+
|
|
|
+ // apostrophes
|
|
|
+ "/(\w)'(\w)/" => '$1’$2', // we dont use #8217; to avoid collision on replace
|
|
|
+
|
|
|
+ // Em dash and ellipses dots
|
|
|
+ '/\s?\-\-\s?/' => '—',
|
|
|
+ '/(\w)\.{3}/' => '$1…',
|
|
|
+
|
|
|
+ // double space after sentences
|
|
|
+ '/(\W) /' => '$1 ',
|
|
|
+
|
|
|
+ // ampersands, if not a character entity
|
|
|
+ '/&(?!#?[a-zA-Z0-9]{2,};)/' => '&'
|
|
|
+ ];
|
|
|
+ if ($locale && !empty($locales[$locale])) {
|
|
|
+ foreach ($table as $key => $val) {
|
|
|
+ $table[$key] = str_replace($locales['default'], $locales[$locale], $val);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return preg_replace(array_keys($this->table), $this->table, $str);
|
|
|
+ return preg_replace(array_keys($table), $table, $str);
|
|
|
}
|
|
|
|
|
|
/**
|