Commit e67c6ca5 authored by Barnaby Walters's avatar Barnaby Walters

Fixed #61, at least for data elements

parent 6486f9a7
......@@ -391,7 +391,7 @@ class Parser {
* @param bool $implied when parsing for implied name for h-*, rules may be slightly different
* @see: https://github.com/glennjones/microformat-shiv/blob/dev/lib/text.js
*/
public function innerText($el, $implied = false) {
public function innerText($el, $implied=false) {
$out = '';
$blockLevelTags = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'hr', 'pre', 'table',
......@@ -401,7 +401,10 @@ class Parser {
'tfoot', 'th', 'thead', 'tr', 'td', 'ul', 'ol', 'dl', 'details');
$excludeTags = array('noframe', 'noscript', 'script', 'style', 'frames', 'frameset');
// PHP DOMDocument doesn’t correctly handle whitespace around elements it doesn’t recognise.
$unsupportedTags = array('data');
if (isset($el->tagName)) {
if (in_array(strtolower($el->tagName), $excludeTags)) {
return $out;
......@@ -437,6 +440,8 @@ class Parser {
// if its a block level tag add an additional space at the end
if (in_array(strtolower($el->tagName), $blockLevelTags)) {
$out .= ' ';
} elseif ($implied and in_array(strtolower($el->tagName), $unsupportedTags)) {
$out .= ' ';
} else if (strtolower($el->tagName) == 'br') {
// else if its a br, replace with newline
$out .= "\n";
......
......@@ -396,4 +396,20 @@ EOT;
$this->assertContains('visibility', $output['items'][0]['properties']['content'][0]['html']);
$this->assertNotContains('visibility', $output['items'][0]['properties']['content'][0]['value']);
}
public function testWhitespaceBetweenElements() {
$input = <<<EOT
<div class="h-entry">
<data class="p-rsvp" value="yes">I'm attending</data>
<a class="u-in-reply-to" href="https://snarfed.org/2014-06-16_homebrew-website-club-at-quip">Homebrew Website Club at Quip</a>
<div class="p-content">Thanks for hosting!</div>
</div>
EOT;
$parser = new Parser($input);
$output = $parser->parse();
$this->assertContains('h-entry', $output['items'][0]['type']);
$this->assertNotContains('attendingHomebrew', $output['items'][0]['properties']['name'][0]);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment