@@ -78,17 +78,43 @@ public function filterHtml(string $content): string
78
78
);
79
79
foreach ($ htmlContentTypes as $ htmlContentType ) {
80
80
/* @var \DOMElement $htmlContentType */
81
- $ innerHTML = '' ;
82
- $ children = $ htmlContentType ->childNodes ;
83
- foreach ($ children as $ child ) {
84
- $ innerHTML .= $ child ->ownerDocument ->saveXML ($ child );
85
- }
86
81
$ htmlContentType ->setAttribute (
87
82
"class " ,
88
83
$ htmlContentType ->getAttribute ("class " ) . " placeholder-html-code "
89
84
);
85
+
86
+ $ innerHTML = $ this ->getChildrenInnerHtml ($ htmlContentType );
87
+
90
88
$ htmlContentType ->nodeValue = htmlentities ($ innerHTML );
91
89
}
92
90
return substr (trim ($ dom ->saveHTML ()), 5 , -6 );
93
91
}
92
+
93
+ /**
94
+ * Get inner HTML of element's children
95
+ *
96
+ * @param \DOMElement $element
97
+ * @return string
98
+ */
99
+ private function getChildrenInnerHtml (\DOMElement $ element ): string
100
+ {
101
+ $ innerHTML = '' ;
102
+ $ childrenIterator = $ element ->childNodes ->getIterator ();
103
+ while ($ childrenIterator ->valid ()) {
104
+ $ child = $ childrenIterator ->current ();
105
+ try {
106
+ $ ownerDocument = $ child ->ownerDocument ;
107
+ } catch (\Error $ error ) {
108
+ $ ownerDocument = null ;
109
+ $ this ->loggerInterface ->critical ($ error ->getMessage ());
110
+ }
111
+ if ($ ownerDocument === null ) {
112
+ $ childrenIterator ->next ();
113
+ continue ;
114
+ }
115
+ $ innerHTML .= $ ownerDocument ->saveXML ($ child );
116
+ $ childrenIterator ->next ();
117
+ }
118
+ return $ innerHTML ;
119
+ }
94
120
}
0 commit comments