File tree Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -33,15 +33,13 @@ class autotitle {
33
33
*/
34
34
public static function extract_title (string $ summary ): string {
35
35
36
- $ summary = trim ($ summary );
37
-
38
36
if ($ summary === '' ) {
39
37
return '' ;
40
38
}
41
39
42
40
$ dom = new \DOMDocument ();
43
41
libxml_use_internal_errors (true );
44
- $ dom ->loadHTML ($ summary );
42
+ $ dom ->loadHTML (' <?xml encoding="utf-8" ?> ' . $ summary );
45
43
libxml_clear_errors ();
46
44
47
45
return static ::find_first_nonempty_text_node_value ($ dom );
@@ -59,7 +57,7 @@ public static function extract_title(string $summary): string {
59
57
public static function find_first_nonempty_text_node_value (\DOMNode $ node ): string {
60
58
61
59
if ($ node ->nodeType == XML_TEXT_NODE ) {
62
- $ text = trim ( $ node ->textContent );
60
+ $ text = ( string ) preg_replace ( ' /^\s+|\s+$/u ' , '' , $ node ->textContent );
63
61
64
62
if ($ text !== '' ) {
65
63
return $ text ;
Original file line number Diff line number Diff line change @@ -79,6 +79,15 @@ public function extract_title_data(): array {
79
79
'summary ' => 'Hello <br> students ' ,
80
80
'title ' => 'Hello ' ,
81
81
],
82
+ 'Multi-byte ' => [
83
+ 'summary ' => "\u{a0}µ déjà \u{a0}ěščřžýáíé \u{a0}" ,
84
+ 'title ' => "µ déjà \u{a0}ěščřžýáíé " ,
85
+ ],
86
+ 'Non-breakable spaces ' => [
87
+ 'summary ' => '<h2> <span style="font-family:tahoma">Lesson 4: Your first game ' . "\xC2\xA0" .
88
+ "\xc2\xa0" . ' </span> </h2> ' ,
89
+ 'title ' => 'Lesson 4: Your first game ' ,
90
+ ],
82
91
];
83
92
}
84
93
}
You can’t perform that action at this time.
0 commit comments