1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of PHP-Typography. |
4
|
|
|
* |
5
|
|
|
* Copyright 2017-2019 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\Node_Fixes; |
28
|
|
|
|
29
|
|
|
use PHP_Typography\DOM; |
30
|
|
|
use PHP_Typography\Settings; |
31
|
|
|
use PHP_Typography\U; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Applies smart ellipses (if enabled). |
35
|
|
|
* |
36
|
|
|
* @author Peter Putzer <[email protected]> |
37
|
|
|
* |
38
|
|
|
* @since 5.0.0 |
39
|
|
|
*/ |
40
|
|
|
class Smart_Ellipses_Fix extends Abstract_Node_Fix { |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Apply the fix to a given textnode. |
44
|
|
|
* |
45
|
|
|
* @param \DOMText $textnode Required. |
46
|
|
|
* @param Settings $settings Required. |
47
|
|
|
* @param bool $is_title Optional. Default false. |
48
|
|
|
*/ |
49
|
2 |
|
public function apply( \DOMText $textnode, Settings $settings, $is_title = false ) { |
50
|
2 |
|
if ( empty( $settings[ Settings::SMART_ELLIPSES ] ) ) { |
51
|
1 |
|
return; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
// Cache textnode content. |
55
|
1 |
|
$node_data = $textnode->data; |
56
|
|
|
|
57
|
1 |
|
$node_data = \str_replace( [ '....', '. . . .' ], '.' . U::ELLIPSIS, $node_data ); |
58
|
1 |
|
$node_data = \str_replace( [ '...', '. . .' ], U::ELLIPSIS, $node_data ); |
59
|
|
|
|
60
|
|
|
// Restore textnode content. |
61
|
1 |
|
$textnode->data = $node_data; |
62
|
1 |
|
} |
63
|
|
|
} |
64
|
|
|
|