|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of PHP-Typography. |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright 2017 Peter Putzer. |
|
6
|
|
|
* |
|
7
|
|
|
* This program is free software; you can redistribute it and/or modify modify |
|
8
|
|
|
* it under the terms of the GNU General Public License as published by |
|
9
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
|
10
|
|
|
* (at your option) any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU General Public License along |
|
18
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc., |
|
19
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
20
|
|
|
* |
|
21
|
|
|
* *** |
|
22
|
|
|
* |
|
23
|
|
|
* @package mundschenk-at/php-typography |
|
24
|
|
|
* @license http://www.gnu.org/licenses/gpl-2.0.html |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
namespace PHP_Typography\Fixes; |
|
28
|
|
|
|
|
29
|
|
|
use PHP_Typography\Settings; |
|
30
|
|
|
|
|
31
|
|
|
use PHP_Typography\Fixes\Node_Fix; |
|
32
|
|
|
use PHP_Typography\Fixes\Token_Fix; |
|
33
|
|
|
|
|
34
|
|
|
use PHP_Typography\Hyphenator\Cache; |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* A registry implementation containing the default fixes for PHP_Typography. |
|
39
|
|
|
* |
|
40
|
|
|
* @author Peter Putzer <[email protected]> |
|
41
|
|
|
* |
|
42
|
|
|
* @since 6.0.0 |
|
43
|
|
|
*/ |
|
44
|
|
|
class Default_Registry extends Registry { |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* An array of CSS classes that are added for ampersands, numbers etc. |
|
48
|
|
|
*/ |
|
49
|
|
|
const DEFAULT_CSS_CLASSES = [ |
|
50
|
|
|
'caps' => 'caps', |
|
51
|
|
|
'numbers' => 'numbers', |
|
52
|
|
|
'amp' => 'amp', |
|
53
|
|
|
'quo' => 'quo', |
|
54
|
|
|
'dquo' => 'dquo', |
|
55
|
|
|
'pull-single' => 'pull-single', |
|
56
|
|
|
'pull-double' => 'pull-double', |
|
57
|
|
|
'push-single' => 'push-single', |
|
58
|
|
|
'push-double' => 'push-double', |
|
59
|
|
|
'numerator' => 'numerator', |
|
60
|
|
|
'denominator' => 'denominator', |
|
61
|
|
|
'ordinal' => 'ordinal', |
|
62
|
|
|
]; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Creates new default registry instance. |
|
66
|
|
|
* |
|
67
|
|
|
* @param Cache|null $cache Optional. A hyphenatation cache instance to use. Default null. |
|
68
|
|
|
* @param string[] $css_classes Optional. An array of CSS classes to use. Defaults to null (i.e. use the predefined classes). |
|
69
|
|
|
*/ |
|
70
|
|
|
public function __construct( Cache $cache = null, array $css_classes = [] ) { |
|
71
|
|
|
parent::__construct(); |
|
72
|
|
|
|
|
73
|
|
|
if ( empty( $css_classes ) ) { |
|
74
|
|
|
$css_classes = self::DEFAULT_CSS_CLASSES; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
// Nodify anything that requires adjacent text awareness here. |
|
78
|
|
|
$this->register_node_fix( new Node_Fixes\Smart_Maths_Fix(), self::CHARACTERS ); |
|
79
|
|
|
$this->register_node_fix( new Node_Fixes\Smart_Diacritics_Fix(), self::CHARACTERS ); |
|
80
|
|
|
$this->register_node_fix( new Node_Fixes\Smart_Quotes_Fix( true ), self::CHARACTERS ); |
|
81
|
|
|
$this->register_node_fix( new Node_Fixes\Smart_Dashes_Fix( true ), self::CHARACTERS ); |
|
82
|
|
|
$this->register_node_fix( new Node_Fixes\Smart_Ellipses_Fix( true ), self::CHARACTERS ); |
|
83
|
|
|
$this->register_node_fix( new Node_Fixes\Smart_Marks_Fix( true ), self::CHARACTERS ); |
|
84
|
|
|
|
|
85
|
|
|
// Keep spacing after smart character replacement. |
|
86
|
|
|
$this->register_node_fix( new Node_Fixes\Single_Character_Word_Spacing_Fix(), self::SPACING_PRE_WORDS ); |
|
87
|
|
|
$this->register_node_fix( new Node_Fixes\Dash_Spacing_Fix(), self::SPACING_PRE_WORDS ); |
|
88
|
|
|
$this->register_node_fix( new Node_Fixes\Unit_Spacing_Fix(), self::SPACING_PRE_WORDS ); |
|
89
|
|
|
$this->register_node_fix( new Node_Fixes\Numbered_Abbreviation_Spacing_Fix(), self::SPACING_PRE_WORDS ); |
|
90
|
|
|
$this->register_node_fix( new Node_Fixes\French_Punctuation_Spacing_Fix(), self::SPACING_PRE_WORDS ); |
|
91
|
|
|
|
|
92
|
|
|
// Some final space manipulation. |
|
93
|
|
|
$this->register_node_fix( new Node_Fixes\Dewidow_Fix(), self::SPACING_POST_WORDS ); |
|
94
|
|
|
$this->register_node_fix( new Node_Fixes\Space_Collapse_Fix(), self::SPACING_POST_WORDS ); |
|
95
|
|
|
|
|
96
|
|
|
// Everything that requires HTML injection occurs here (functions above assume tag-free content) |
|
97
|
|
|
// pay careful attention to functions below for tolerance of injected tags. |
|
98
|
|
|
$this->register_node_fix( new Node_Fixes\Smart_Ordinal_Suffix_Fix( $css_classes['ordinal'] ), self::HTML_INSERTION ); // call before "style_numbers" and "smart_fractions". |
|
99
|
|
|
$this->register_node_fix( new Node_Fixes\Smart_Exponents_Fix(), self::HTML_INSERTION ); // call before "style_numbers". |
|
100
|
|
|
$this->register_node_fix( new Node_Fixes\Smart_Fractions_Fix( $css_classes['numerator'], $css_classes['denominator'] ), self::HTML_INSERTION ); // call before "style_numbers" and after "smart_ordinal_suffix". |
|
101
|
|
|
$this->register_node_fix( new Node_Fixes\Style_Caps_Fix( $css_classes['caps'] ), self::HTML_INSERTION ); // Call before "style_numbers". |
|
102
|
|
|
$this->register_node_fix( new Node_Fixes\Style_Numbers_Fix( $css_classes['numbers'] ), self::HTML_INSERTION ); // Call after "smart_ordinal_suffix", "smart_exponents", "smart_fractions", and "style_caps". |
|
103
|
|
|
$this->register_node_fix( new Node_Fixes\Style_Ampersands_Fix( $css_classes['amp'] ), self::HTML_INSERTION ); |
|
104
|
|
|
$this->register_node_fix( new Node_Fixes\Style_Initial_Quotes_Fix( $css_classes['quo'], $css_classes['dquo'] ), self::HTML_INSERTION ); |
|
105
|
|
|
$this->register_node_fix( new Node_Fixes\Style_Hanging_Punctuation_Fix( $css_classes['push-single'], $css_classes['push-double'], $css_classes['pull-single'], $css_classes['pull-double'] ), self::HTML_INSERTION ); |
|
106
|
|
|
|
|
107
|
|
|
// Register token fixes. |
|
108
|
|
|
$this->register_token_fix( new Token_Fixes\Wrap_Hard_Hyphens_Fix() ); |
|
109
|
|
|
$this->register_token_fix( new Token_Fixes\Hyphenate_Compounds_Fix( $cache ) ); |
|
110
|
|
|
$this->register_token_fix( new Token_Fixes\Hyphenate_Fix( $cache ) ); |
|
111
|
|
|
$this->register_token_fix( new Token_Fixes\Wrap_URLs_Fix( $cache ) ); |
|
112
|
|
|
$this->register_token_fix( new Token_Fixes\Wrap_Emails_Fix() ); |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|