File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed
Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -897,10 +897,17 @@ public function parseE(\DOMElement $e) {
897897 // TODO: as it is this is not relative to only children, make this .// and rerun tests
898898 $ this ->resolveChildUrls ($ e );
899899
900- $ html = '' ;
901- foreach ($ e ->childNodes as $ node ) {
902- $ html .= $ node ->ownerDocument ->saveHTML ($ node );
903- }
900+ // Temporarily move all descendants into a separate DocumentFragment.
901+ // This way we can DOMDocument::saveHTML on the entire collection at once.
902+ // Running DOMDocument::saveHTML per node may add whitespace that isn't in source.
903+ // See https://stackoverflow.com/q/38317903
904+ $ innerNodes = $ e ->ownerDocument ->createDocumentFragment ();
905+ while ($ e ->hasChildNodes ()) {
906+ $ innerNodes ->appendChild ($ e ->firstChild );
907+ }
908+ $ html = $ e ->ownerDocument ->saveHtml ($ innerNodes );
909+ // Put the nodes back in place.
910+ $ e ->appendChild ($ innerNodes );
904911
905912 $ return = array (
906913 'html ' => unicodeTrim ($ html ),
Original file line number Diff line number Diff line change @@ -696,5 +696,12 @@ public function testMultiLevelRecursion() {
696696 $ this ->assertEquals ('Comment D ' , $ three ['children ' ][1 ]['properties ' ]['name ' ][0 ]);
697697 $ this ->assertEquals ('Four ' , $ output ['items ' ][0 ]['children ' ][3 ]['properties ' ]['name ' ][0 ]);
698698 }
699+
700+ public function testNoErrantWhitespaceOnEHtml ()
701+ {
702+ $ input = '<div class="h-entry"><div class="e-content"><p>1</p><p>2</p></div></div> ' ;
703+ $ output = Mf2 \parse ($ input );
704+ $ this ->assertEquals ('<p>1</p><p>2</p> ' , $ output ['items ' ][0 ]['properties ' ]['content ' ][0 ]['html ' ]);
705+ }
699706}
700707
You can’t perform that action at this time.
0 commit comments