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 |
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\Node_Fixes; |
28
|
|
|
|
29
|
|
|
use PHP_Typography\DOM; |
30
|
|
|
use PHP_Typography\Settings; |
31
|
|
|
use PHP_Typography\U; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Wraps words of all caps (may include numbers) in <span class="caps"> if enabled. |
35
|
|
|
* |
36
|
|
|
* Call before style_numbers().Only call if you are certain that no html tags have been |
37
|
|
|
* injected containing capital letters. |
38
|
|
|
* |
39
|
|
|
* @author Peter Putzer <[email protected]> |
40
|
|
|
* |
41
|
|
|
* @since 5.0.0 |
42
|
|
|
*/ |
43
|
|
|
class Style_Caps_Fix extends Simple_Style_Fix { |
44
|
|
|
/* |
45
|
|
|
// \p{Lu} equals upper case letters and should match non english characters; since PHP 4.4.0 and 5.1.0 |
46
|
|
|
// for more info, see http://www.regextester.com/pregsyntax.html#regexp.reference.unicode |
47
|
|
|
$this->components[ Settings::STYLE_CAPS ] = ' |
48
|
|
|
(?<![\w\-_'.U::ZERO_WIDTH_SPACE.U::SOFT_HYPHEN.']) |
49
|
|
|
# negative lookbehind assertion |
50
|
|
|
( |
51
|
|
|
(?: # CASE 1: " 9A " |
52
|
|
|
[0-9]+ # starts with at least one number |
53
|
|
|
\p{Lu} # must contain at least one capital letter |
54
|
|
|
(?:\p{Lu}|[0-9]|\-|_|'.U::ZERO_WIDTH_SPACE.'|'.U::SOFT_HYPHEN.')* |
55
|
|
|
# may be followed by any number of numbers capital letters, hyphens, underscores, zero width spaces, or soft hyphens |
56
|
|
|
) |
57
|
|
|
| |
58
|
|
|
(?: # CASE 2: " A9 " |
59
|
|
|
\p{Lu} # starts with capital letter |
60
|
|
|
(?:\p{Lu}|[0-9]) # must be followed a number or capital letter |
61
|
|
|
(?:\p{Lu}|[0-9]|\-|_|'.U::ZERO_WIDTH_SPACE.'|'.U::SOFT_HYPHEN.')* |
62
|
|
|
# may be followed by any number of numbers capital letters, hyphens, underscores, zero width spaces, or soft hyphens |
63
|
|
|
|
64
|
|
|
) |
65
|
|
|
) |
66
|
|
|
(?![\w\-_'.U::ZERO_WIDTH_SPACE.U::SOFT_HYPHEN.']) |
67
|
|
|
# negative lookahead assertion |
68
|
|
|
'; // required modifiers: x (multiline pattern) u (utf8) |
69
|
|
|
*/ |
70
|
|
|
|
71
|
|
|
// Servers with PCRE compiled without "--enable-unicode-properties" fail at \p{Lu} by returning an empty string (this leaving the screen void of text |
72
|
|
|
// thus are testing this alternative. |
73
|
|
|
const REGEX = '/ |
74
|
|
|
(?<![\w' . self::COMBINING_MARKS . ']) # negative lookbehind assertion |
75
|
|
|
( |
76
|
|
|
(?: # CASE 1: " 9A " |
77
|
|
|
[0-9]+ # starts with at least one number |
78
|
|
|
(?:[' . self::COMBINING_MARKS . '])* |
79
|
|
|
# may contain hyphens, underscores, zero width spaces, or soft hyphens, |
80
|
|
|
[A-ZÀ-ÖØ-Ý] # but must contain at least one capital letter |
81
|
|
|
(?:[A-ZÀ-ÖØ-Ý]|[0-9]|[' . self::COMBINING_MARKS . '])* |
82
|
|
|
# may be followed by any number of numbers capital letters, hyphens, underscores, zero width spaces, or soft hyphens |
83
|
|
|
) |
84
|
|
|
| |
85
|
|
|
(?: # CASE 2: " A9 " |
86
|
|
|
[A-ZÀ-ÖØ-Ý] # starts with capital letter |
87
|
|
|
(?:[A-ZÀ-ÖØ-Ý]|[0-9]) # must be followed a number or capital letter |
88
|
|
|
(?:[A-ZÀ-ÖØ-Ý]|[0-9]|[' . self::COMBINING_MARKS . '])* |
89
|
|
|
# may be followed by any number of numbers capital letters, hyphens, underscores, zero width spaces, or soft hyphens |
90
|
|
|
) |
91
|
|
|
) |
92
|
|
|
(?![\w' . self::COMBINING_MARKS . ']) # negative lookahead assertion |
93
|
|
|
/Sxu'; |
94
|
|
|
|
95
|
|
|
const COMBINING_MARKS = '\-_' . U::HYPHEN . U::SOFT_HYPHEN . U::ZERO_WIDTH_SPACE; // Needs to be part of character class. |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Creates a new node fix with a class. |
99
|
|
|
* |
100
|
|
|
* @param string $css_class HTML class used in markup. |
101
|
|
|
* @param bool $feed_compatible Optional. Default false. |
102
|
|
|
*/ |
103
|
12 |
|
public function __construct( $css_class, $feed_compatible = false ) { |
104
|
12 |
|
parent::__construct( self::REGEX, Settings::STYLE_CAPS, $css_class, $feed_compatible ); |
105
|
12 |
|
} |
106
|
|
|
} |
107
|
|
|
|