From 9f5765282481ecf79a67eacfdafae2d103704571 Mon Sep 17 00:00:00 2001 From: MathisMARION Date: Sat, 30 Nov 2024 17:18:26 +0100 Subject: [PATCH] Do not colorize commit logs Patch e-mails typically include a commit log as a header, which may contain arbitrary text including patterns that highlight.js can interpret as a diff. I have typically encountered this when a commit log line starts with a commandline option or a bullet point. --- scripts/coloring.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/scripts/coloring.js b/scripts/coloring.js index bd69c3f..9d5fb24 100644 --- a/scripts/coloring.js +++ b/scripts/coloring.js @@ -14,7 +14,21 @@ const coloring = { const preNodes = document.querySelectorAll("body > div > pre"); for (const pre of preNodes) { - for (let i = 0; i < pre.childNodes.length; i++) { + let i, j = -1; + + for (i = 0; i < pre.childNodes.length && j < 0; i++) { + if (pre.childNodes[i].nodeName !== "#text") { + /* + * man git-format-patch: The log message and the patch are + * separated by a line with a three-dash line. + */ + j = pre.childNodes[i].textContent.search(/^---$/m); + } + } + if (j >= 0) { + pre.childNodes[i - 1].splitText(j + '---'.length); + } + for (i = 0; i < pre.childNodes.length; i++) { if (pre.childNodes[i].nodeName === "#text") { const span = document.createElement("SPAN");