refac: disable single tilde

This commit is contained in:
Timothy Jaeryang Baek 2025-11-23 17:16:10 -05:00
parent a4c3fa70c1
commit b0491886bc
2 changed files with 31 additions and 0 deletions

View file

@ -5,6 +5,7 @@
import markedExtension from '$lib/utils/marked/extension'; import markedExtension from '$lib/utils/marked/extension';
import markedKatexExtension from '$lib/utils/marked/katex-extension'; import markedKatexExtension from '$lib/utils/marked/katex-extension';
import { disableSingleTilde } from '$lib/utils/marked/strikethrough-extension';
import { mentionExtension } from '$lib/utils/marked/mention-extension'; import { mentionExtension } from '$lib/utils/marked/mention-extension';
import MarkdownTokens from './Markdown/MarkdownTokens.svelte'; import MarkdownTokens from './Markdown/MarkdownTokens.svelte';
@ -38,6 +39,7 @@
marked.use(markedKatexExtension(options)); marked.use(markedKatexExtension(options));
marked.use(markedExtension(options)); marked.use(markedExtension(options));
marked.use(disableSingleTilde);
marked.use({ marked.use({
extensions: [mentionExtension({ triggerChar: '@' }), mentionExtension({ triggerChar: '#' })] extensions: [mentionExtension({ triggerChar: '@' }), mentionExtension({ triggerChar: '#' })]
}); });

View file

@ -0,0 +1,29 @@
export const disableSingleTilde = {
tokenizer: {
del(src) {
// 1. First check for the REAL strikethrough: ~~text~~
const doubleMatch = /^~~(?=\S)([\s\S]*?\S)~~/.exec(src);
if (doubleMatch) {
return {
type: 'del',
raw: doubleMatch[0],
text: doubleMatch[1],
tokens: this.lexer.inlineTokens(doubleMatch[1])
};
}
// 2. Check for single-tilde: ~text~
const singleMatch = /^~(?=\S)([\s\S]*?\S)~/.exec(src);
if (singleMatch) {
// return a plain-text token, NOT del
return {
type: 'text',
raw: singleMatch[0],
text: singleMatch[0] // include both tildes as literal text
};
}
return false;
}
}
};