File tree Expand file tree Collapse file tree 4 files changed +28
-3
lines changed
Expand file tree Collapse file tree 4 files changed +28
-3
lines changed Original file line number Diff line number Diff line change 77 - 7.1
88 - 7.2
99 - nightly
10+ env :
11+ - COMPOSER_REQUIRE=""
12+ - COMPOSER_REQUIRE="composer require masterminds/html5"
13+ install :
14+ - $COMPOSER_REQUIRE
1015before_script : composer install
Original file line number Diff line number Diff line change @@ -337,8 +337,13 @@ class Parser {
337337 public function __construct ($ input , $ url = null , $ jsonMode = false ) {
338338 libxml_use_internal_errors (true );
339339 if (is_string ($ input )) {
340- $ doc = new DOMDocument ();
341- @$ doc ->loadHTML (unicodeToHtmlEntities ($ input ));
340+ if (class_exists ('Masterminds \\HTML5 ' )) {
341+ $ doc = new \Masterminds \HTML5 (array ('disable_html_ns ' => true ));
342+ $ doc = $ doc ->loadHTML ($ input );
343+ } else {
344+ $ doc = new DOMDocument ();
345+ @$ doc ->loadHTML (unicodeToHtmlEntities ($ input ));
346+ }
342347 } elseif (is_a ($ input , 'DOMDocument ' )) {
343348 $ doc = $ input ;
344349 } else {
Original file line number Diff line number Diff line change 2323 },
2424 "license" : " CC0-1.0" ,
2525 "suggest" : {
26- "barnabywalters/mf-cleaner" : " To more easily handle the canonical data php-mf2 gives you"
26+ "barnabywalters/mf-cleaner" : " To more easily handle the canonical data php-mf2 gives you" ,
27+ "masterminds/html5" : " Alternative HTML parser for PHP, for better HTML5 support."
2728 }
2829}
Original file line number Diff line number Diff line change @@ -776,5 +776,19 @@ public function testUniqueAndAlphabeticalMfClasses() {
776776 $ this ->assertEquals (array ('h-cite ' , 'h-entry ' ), $ output ['items ' ][0 ]['type ' ]);
777777 }
778778
779+ /**
780+ * The default DOMDocument parser will trip here because it does not know HTML5 elements.
781+ * @see https://html.spec.whatwg.org/#optional-tags:the-p-element
782+ **/
783+ public function testHtml5OptionalPEndTag () {
784+ if (!class_exists ('Masterminds \\HTML5 ' )) {
785+ $ this ->markTestSkipped ('masterminds/html5 is required for this test. ' );
786+ }
787+ $ input = '<div class="h-entry"><p class="p-name">Name<article>Not Name</article></div> ' ;
788+ $ output = Mf2 \parse ($ input );
789+
790+ $ this ->assertEquals ('Name ' , $ output ['items ' ][0 ]['properties ' ]['name ' ][0 ]);
791+ }
792+
779793}
780794
You can’t perform that action at this time.
0 commit comments