Add <code> if it's missing

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
pull/21833/head
Šimon Brandner 2021-02-22 13:43:57 +01:00
parent 87a2454556
commit 6149567c62
No known key found for this signature in database
GPG Key ID: 9760693FDD98A790
1 changed files with 8 additions and 0 deletions

View File

@ -96,6 +96,14 @@ export default class TextualBody extends React.Component {
const pres = ReactDOM.findDOMNode(this).getElementsByTagName("pre"); const pres = ReactDOM.findDOMNode(this).getElementsByTagName("pre");
if (pres.length > 0) { if (pres.length > 0) {
for (let i = 0; i < pres.length; i++) { for (let i = 0; i < pres.length; i++) {
let code = pres[i].getElementsByTagName("code")[0];
// Add code element if it's missing
if (!code) {
code = document.createElement("code");
code.innerHTML = pres[i].innerHTML;
pres[i].innerHTML = "";
pres[i].appendChild(code);
}
// If there already is a div wrapping the codeblock we want to skip this. // If there already is a div wrapping the codeblock we want to skip this.
// This happens after the codeblock was edited. // This happens after the codeblock was edited.
if (pres[i].parentNode.className == "mx_EventTile_pre_container") continue; if (pres[i].parentNode.className == "mx_EventTile_pre_container") continue;