Add _addCodeElement method
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
parent
6149567c62
commit
c965119410
1 changed files with 8 additions and 7 deletions
|
@ -96,14 +96,8 @@ 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
|
// Add code element if it's missing
|
||||||
if (!code) {
|
if (!pres[i].getElementsByTagName("code")[0]) this._addCodeElement(pres[i]);
|
||||||
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;
|
||||||
|
@ -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) {
|
_addCodeExpansionButton(div, pre) {
|
||||||
// Calculate how many percent does the pre element take up.
|
// Calculate how many percent does the pre element take up.
|
||||||
// If it's less than 30% we don't add the expansion button.
|
// If it's less than 30% we don't add the expansion button.
|
||||||
|
|
Loading…
Reference in a new issue