File tree 2 files changed +20
-1
lines changed
2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,11 @@ class Syllable
62
62
private $ excludes = array ();
63
63
private $ includes = array ();
64
64
65
+ /**
66
+ * @var int
67
+ */
68
+ private $ libxmlOptions = 0 ;
69
+
65
70
/**
66
71
* Create a new Syllable class, with defaults
67
72
*
@@ -195,6 +200,16 @@ public function getMinWordLength()
195
200
return $ this ->min_word_length ;
196
201
}
197
202
203
+ /**
204
+ * Options to use for HTML parsing by libxml
205
+ * @param integer $libxmlOptions
206
+ * @see https://www.php.net/manual/de/libxml.constants.php
207
+ */
208
+ public function setLibxmlOptions ($ libxmlOptions )
209
+ {
210
+ $ this ->libxmlOptions = $ libxmlOptions ;
211
+ }
212
+
198
213
private static function initEncoding ()
199
214
{
200
215
if (self ::$ encoding ) {
@@ -436,7 +451,7 @@ public function hyphenateHtml($html)
436
451
{
437
452
$ dom = new \DOMDocument ();
438
453
$ dom ->resolveExternals = true ;
439
- $ dom ->loadHTML ($ html );
454
+ $ dom ->loadHTML ($ html, $ this -> libxmlOptions );
440
455
441
456
// filter excludes
442
457
$ xpath = new \DOMXPath ($ dom );
Original file line number Diff line number Diff line change @@ -222,6 +222,10 @@ public function testHyphenateHtml()
222
222
$ this ->assertEquals ('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> '
223
223
. "\n" . '<html><body><p>Ridicu-lous-ly <b class="unsplittable">com-pli-cat-ed</b> meta-text</p></body></html> '
224
224
. "\n" , $ this ->object ->hyphenateHtml ('Ridiculously <b class="unsplittable">complicated</b> metatext ' ));
225
+
226
+ $ this ->object ->setLibxmlOptions (LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD );
227
+ $ this ->assertEquals ('<p>Ridicu-lous-ly <b class="unsplittable">com-pli-cat-ed</b> meta-text</p> '
228
+ . "\n" , $ this ->object ->hyphenateHtml ('Ridiculously <b class="unsplittable">complicated</b> metatext ' ));
225
229
}
226
230
227
231
public function testCaseInsensitivity ()
You can’t perform that action at this time.
0 commit comments