Skip to content

Commit bd65bcf

Browse files
committed
when parsing e-content, output result as HTML
* adds failing test for parsing 'one<br>two' (currently converts it to 'one<br></br>two' * fixes parser by using saveHTML instead of C14N
1 parent d5a3f61 commit bd65bcf

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Mf2/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ public function parseE(\DOMElement $e) {
736736

737737
$html = '';
738738
foreach ($e->childNodes as $node) {
739-
$html .= $node->C14N();
739+
$html .= $node->ownerDocument->saveHTML($node);
740740
}
741741

742742
return array(

tests/Mf2/ParserTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,20 @@ public function testParseEResolvesRelativeLinks() {
9292
$parser = new Parser($input, 'http://example.com');
9393
$output = $parser->parse();
9494

95-
$this->assertEquals('Blah blah <a href="http://example.com/a-url">thing</a>. <object data="http://example.com/object"></object> <img src="http://example.com/img"></img>', $output['items'][0]['properties']['content'][0]['html']);
95+
$this->assertEquals('Blah blah <a href="http://example.com/a-url">thing</a>. <object data="http://example.com/object"></object> <img src="http://example.com/img">', $output['items'][0]['properties']['content'][0]['html']);
9696
$this->assertEquals('Blah blah thing. http://example.com/img', $output['items'][0]['properties']['content'][0]['value']);
9797
}
9898

99+
public function testParseEWithBR() {
100+
$input = '<div class="h-entry"><div class="e-content">Here is content with two lines.<br>The br tag should not be converted to an XML br/br element.</div></div>';
101+
//$parser = new Parser($input);
102+
$output = Mf2\parse($input);
103+
104+
$this->assertArrayHasKey('content', $output['items'][0]['properties']);
105+
$this->assertEquals('Here is content with two lines.<br>The br tag should not be converted to an XML br/br element.', $output['items'][0]['properties']['content'][0]['html']);
106+
$this->assertEquals('Here is content with two lines.'."\n".'The br tag should not be converted to an XML br/br element.', $output['items'][0]['properties']['content'][0]['value']);
107+
}
108+
99109
/**
100110
* @group parseH
101111
*/

0 commit comments

Comments
 (0)