Fix convert code blocs from markdown/html to bbcode

This commit is contained in:
Harald Eilertsen
2024-02-06 18:39:51 +01:00
parent 983f063d33
commit ec19ee9d82
3 changed files with 21 additions and 2 deletions

View File

@@ -127,8 +127,15 @@ function html2bbcode($message)
$xpath = new DomXPath($doc);
$list = $xpath->query("//pre");
foreach ($list as $node)
$node->nodeValue = str_replace("\n", "\r", $node->nodeValue);
foreach ($list as $node) {
if ($node->hasChildNodes()) {
foreach ($node->childNodes as $child) {
$child->nodeValue = str_replace("\n", "\r", $child->nodeValue);
}
} else {
$node->nodeValue = str_replace("\n", "\r", $node->nodeValue);
}
}
$message = $doc->saveHTML();
$message = str_replace(array("\n<", ">\n", "\r", "\n", "\xC3\x82\xC2\xA0"), array("<", ">", "<br />", " ", ""), $message);