From 4017293346f4f8ffadf756306bca1a0ee07fee08 Mon Sep 17 00:00:00 2001 From: MathisMARION Date: Sat, 30 Nov 2024 17:18:26 +0100 Subject: [PATCH 1/2] 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..0d20b15 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 < pre.childNodes.length; i++) { if (pre.childNodes[i].nodeName === "#text") { const span = document.createElement("SPAN"); From 4a17b5e95a2cf42139bcc9785dcdd897f220a74c Mon Sep 17 00:00:00 2001 From: Qeole Date: Tue, 3 Dec 2024 20:42:46 +0000 Subject: [PATCH 2/2] Fix ESLint reports --- scripts/coloring.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/coloring.js b/scripts/coloring.js index 0d20b15..37f96d3 100644 --- a/scripts/coloring.js +++ b/scripts/coloring.js @@ -14,7 +14,8 @@ const coloring = { const preNodes = document.querySelectorAll("body > div > pre"); for (const pre of preNodes) { - let i, j = -1; + let i; + let j = -1; for (i = 0; i < pre.childNodes.length && j < 0; i++) { if (pre.childNodes[i].nodeName === "#text") { @@ -26,7 +27,7 @@ const coloring = { } } if (j >= 0) { - pre.childNodes[i - 1].splitText(j + '---'.length); + pre.childNodes[i - 1].splitText(j + "---".length); } for (; i < pre.childNodes.length; i++) { if (pre.childNodes[i].nodeName === "#text") {