From c965119410ffeb4be0a5d73d22bf593a51dcdecf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Tue, 23 Feb 2021 07:40:53 +0100 Subject: [PATCH] Add _addCodeElement method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/components/views/messages/TextualBody.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/components/views/messages/TextualBody.js b/src/components/views/messages/TextualBody.js index 4223b9cbb8..c6352e0e67 100644 --- a/src/components/views/messages/TextualBody.js +++ b/src/components/views/messages/TextualBody.js @@ -96,14 +96,8 @@ export default class TextualBody extends React.Component { const pres = ReactDOM.findDOMNode(this).getElementsByTagName("pre"); if (pres.length > 0) { 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 (!pres[i].getElementsByTagName("code")[0]) this._addCodeElement(pres[i]); // If there already is a div wrapping the codeblock we want to skip this. // This happens after the codeblock was edited. if (pres[i].parentNode.className == "mx_EventTile_pre_container") continue; @@ -136,6 +130,13 @@ export default class TextualBody extends React.Component { } } + _addCodeElement(pre) { + const code = document.createElement("code"); + code.innerHTML = pre.innerHTML; + pre.innerHTML = ""; + pre.appendChild(code); + } + _addCodeExpansionButton(div, pre) { // Calculate how many percent does the pre element take up. // If it's less than 30% we don't add the expansion button.