Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ php:
- 7.1
- 7.2
- nightly
env:
- COMPOSER_REQUIRE=""
- COMPOSER_REQUIRE="composer require masterminds/html5"
install:
- $COMPOSER_REQUIRE
before_script: composer install
9 changes: 7 additions & 2 deletions Mf2/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,13 @@ class Parser {
public function __construct($input, $url = null, $jsonMode = false) {
libxml_use_internal_errors(true);
if (is_string($input)) {
$doc = new DOMDocument();
@$doc->loadHTML(unicodeToHtmlEntities($input));
if (class_exists('Masterminds\\HTML5')) {
$doc = new \Masterminds\HTML5(array('disable_html_ns' => true));
$doc = $doc->loadHTML($input);
} else {
$doc = new DOMDocument();
@$doc->loadHTML(unicodeToHtmlEntities($input));
}
} elseif (is_a($input, 'DOMDocument')) {
$doc = $input;
} else {
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
},
"license": "CC0-1.0",
"suggest": {
"barnabywalters/mf-cleaner": "To more easily handle the canonical data php-mf2 gives you"
"barnabywalters/mf-cleaner": "To more easily handle the canonical data php-mf2 gives you",
"masterminds/html5": "Alternative HTML parser for PHP, for better HTML5 support."
}
}
14 changes: 14 additions & 0 deletions tests/Mf2/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -776,5 +776,19 @@ public function testUniqueAndAlphabeticalMfClasses() {
$this->assertEquals(array('h-cite', 'h-entry'), $output['items'][0]['type']);
}

/**
* The default DOMDocument parser will trip here because it does not know HTML5 elements.
* @see https://html.spec.whatwg.org/#optional-tags:the-p-element
**/
public function testHtml5OptionalPEndTag() {
if (!class_exists('Masterminds\\HTML5')) {
$this->markTestSkipped('masterminds/html5 is required for this test.');
}
$input = '<div class="h-entry"><p class="p-name">Name<article>Not Name</article></div>';
$output = Mf2\parse($input);

$this->assertEquals('Name', $output['items'][0]['properties']['name'][0]);
}

}