mirror of
https://github.com/element-hq/element-web
synced 2024-11-25 02:35:48 +03:00
Persist code block language when editing
Signed-off-by: Tulir Asokan <tulir@maunium.net>
This commit is contained in:
parent
385e83fdbc
commit
a160bdf4df
1 changed files with 10 additions and 1 deletions
|
@ -58,7 +58,16 @@ function parseLink(a, partCreator) {
|
|||
|
||||
function parseCodeBlock(n, partCreator) {
|
||||
const parts = [];
|
||||
const preLines = ("```\n" + n.textContent + "```").split("\n");
|
||||
let language = "";
|
||||
if (n.firstChild && n.firstChild.nodeName === "CODE") {
|
||||
for (const className of n.firstChild.classList) {
|
||||
if (className.startsWith("language-")) {
|
||||
language = className.substr("language-".length);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
const preLines = ("```" + language + "\n" + n.textContent + "```").split("\n");
|
||||
preLines.forEach((l, i) => {
|
||||
parts.push(partCreator.plain(l));
|
||||
if (i < preLines.length - 1) {
|
||||
|
|
Loading…
Reference in a new issue