mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-11 20:05:19 +00:00
refac: disable single tilde
This commit is contained in:
parent
a4c3fa70c1
commit
b0491886bc
2 changed files with 31 additions and 0 deletions
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
import markedExtension from '$lib/utils/marked/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 MarkdownTokens from './Markdown/MarkdownTokens.svelte';
|
||||
|
|
@ -38,6 +39,7 @@
|
|||
|
||||
marked.use(markedKatexExtension(options));
|
||||
marked.use(markedExtension(options));
|
||||
marked.use(disableSingleTilde);
|
||||
marked.use({
|
||||
extensions: [mentionExtension({ triggerChar: '@' }), mentionExtension({ triggerChar: '#' })]
|
||||
});
|
||||
|
|
|
|||
29
src/lib/utils/marked/strikethrough-extension.ts
Normal file
29
src/lib/utils/marked/strikethrough-extension.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
};
|
||||
Loading…
Reference in a new issue