From 699af44edf8632f8ed33eb50d74ae3ee3f9a37b0 Mon Sep 17 00:00:00 2001 From: Paul d'Aoust Date: Thu, 28 Nov 2024 14:54:35 -0800 Subject: [PATCH] experiment: remove cspell directives from code blocks --- 11ty-extensions/eleventy-transforms.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/11ty-extensions/eleventy-transforms.js b/11ty-extensions/eleventy-transforms.js index 6229ba48f..29573f12e 100644 --- a/11ty-extensions/eleventy-transforms.js +++ b/11ty-extensions/eleventy-transforms.js @@ -47,7 +47,9 @@ export default function(eleventyConfig) { pre.className += ' hljs-container'; const code = pre.querySelector('code'); const maybeLanguage = code.className.match(/(?<=\blanguage-)[A-Za-z0-9_-]+/); - const blockText = he.decode(code.textContent); + let blockText = he.decode(code.textContent); + // Erase cspell directives from sample code. + blockText = blockText.replace(/(#|\/\/|\/\*)\s+(cspell|spell-?checker):\s*[a-z-]+(\s+\*\/)?/i, ""); if (maybeLanguage) { code.innerHTML = hljs.highlight(blockText, {language: maybeLanguage[0]}).value; } else {