Code blocks uploaded as attachments when too long

This commit is contained in:
Cadence Ember
2026-05-13 14:38:14 +12:00
parent 191a98e1dc
commit 4815d28aa4
2 changed files with 35 additions and 1 deletions
+3 -1
View File
@@ -892,7 +892,9 @@ async function eventToMessage(event, guild, channel, di) {
}
// Check for incompatible backticks in code blocks
let preNode
if (node.nodeType === 3 && node.nodeValue.includes("```") && (preNode = nodeIsChildOf(node, ["PRE"]))) {
let isBackticksTextInPre = node.nodeType === 3 && node.nodeValue.includes("```") && (preNode = nodeIsChildOf(node, ["PRE"]))
let isLongPre = node.tagName === "PRE" && node.textContent.length > 1800 && (preNode = node)
if (isBackticksTextInPre || isLongPre) {
if (preNode.firstChild?.nodeName === "CODE") {
let ext = preNode.firstChild.className.match(/language-(\S+)/)?.[1]
if (!dUtils.supportedPlaintextPreviewExtensions.has(ext)) ext = "txt"