1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of PHP-Typography. |
4
|
|
|
* |
5
|
|
|
* Copyright 2018 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\Token_Fixes; |
28
|
|
|
|
29
|
|
|
use PHP_Typography\Fixes\Token_Fix; |
30
|
|
|
use PHP_Typography\Settings; |
31
|
|
|
use PHP_Typography\Text_Parser\Token; |
32
|
|
|
use PHP_Typography\U; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Replaces hyphen-minus with proper hyphen. |
36
|
|
|
* |
37
|
|
|
* @author Peter Putzer <[email protected]> |
38
|
|
|
* |
39
|
|
|
* @since 6.3.0 |
40
|
|
|
*/ |
41
|
|
|
class Smart_Dashes_Hyphen_Fix extends Abstract_Token_Fix { |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Creates a new fix instance. |
45
|
|
|
* |
46
|
|
|
* @param bool $feed_compatible Optional. Default false. |
47
|
|
|
*/ |
48
|
1 |
|
public function __construct( $feed_compatible = false ) { |
49
|
1 |
|
parent::__construct( Token_Fix::MIXED_WORDS, $feed_compatible ); |
50
|
1 |
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Apply the tweak to a given textnode. |
54
|
|
|
* |
55
|
|
|
* @param Token[] $tokens Required. |
56
|
|
|
* @param Settings $settings Required. |
57
|
|
|
* @param bool $is_title Optional. Default false. |
58
|
|
|
* @param \DOMText|null $textnode Optional. Default null. |
59
|
|
|
* |
60
|
|
|
* @return Token[] An array of tokens. |
61
|
|
|
*/ |
62
|
6 |
|
public function apply( array $tokens, Settings $settings, $is_title = false, \DOMText $textnode = null ) { |
63
|
6 |
|
if ( ! empty( $settings[ Settings::SMART_DASHES ] ) ) { |
64
|
3 |
|
foreach ( $tokens as $index => $text_token ) { |
65
|
|
|
// Handled here because we need to know we are inside a word and not a URL. |
66
|
3 |
|
$tokens[ $index ] = $text_token->with_value( \str_replace( '-', U::HYPHEN, $text_token->value ) ); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
6 |
|
return $tokens; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|