From 9559a6febce8f1b2b5efb2c6d4ebf29484dce141 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 23 Sep 2024 22:54:34 -0300 Subject: content: transformContent: override Tokenizer.url, ignore emails --- src/content/dependencies/transformContent.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/content/dependencies') diff --git a/src/content/dependencies/transformContent.js b/src/content/dependencies/transformContent.js index 5f803a3b..4a0a4985 100644 --- a/src/content/dependencies/transformContent.js +++ b/src/content/dependencies/transformContent.js @@ -6,6 +6,21 @@ import {Marked} from 'marked'; const commonMarkedOptions = { headerIds: false, mangle: false, + + tokenizer: { + url(src) { + // Don't link emails + const cap = this.rules.inline.url.exec(src); + if (cap?.[2] === '@') return; + + // Use normal tokenizer url behavior otherwise + // Note that super.url doesn't work here because marked is binding or + // applying this function on the tokenizer instance - super.prop would + // just read the prototype of the containing object literal, not the + // rebound tokenizer. (Thanks MDN.) + return Object.getPrototypeOf(this).url.call(this, src); + }, + }, }; const multilineMarked = new Marked({ -- cgit 1.3.0-6-gf8a5