From 0eba80d43ecae9977177a6e8efd835b598bfdf32 Mon Sep 17 00:00:00 2001 From: Shea Duma Date: Fri, 24 Apr 2026 08:03:55 +0300 Subject: [PATCH] add more checks for paran --- src/app/components/editor/output.ts | 4 ++-- src/app/plugins/markdown/inline/rules.ts | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/app/components/editor/output.ts b/src/app/components/editor/output.ts index d529867c2..d6a7f1e0f 100644 --- a/src/app/components/editor/output.ts +++ b/src/app/components/editor/output.ts @@ -198,7 +198,7 @@ const elementToPlainText = (node: CustomElement, children: string): string => { }; const SPOILERINPUTREGEX = /\|\|.+?\|\|/g; -const LINKINPUTREGEX = /?( |$)/g; +const LINKINPUTREGEX = /?( |$|\))/g; /** * convert slate internal representation to a plain text string that can be sent to the server @@ -319,7 +319,7 @@ export const getLinks = (editor: Editor): string[] | undefined => { let { text } = node; const urlsMatch = text.match(LINKINPUTREGEX); let urls = urlsMatch ? [...new Set(urlsMatch)] : undefined; - urls = urls?.map((url) => (url = url.replace(/(.+?) /g, '$1'))); + urls = urls?.map((url) => (url = url.replace(/(.+?)[ |)]/g, '$1'))); urls = urls?.filter((url) => !(url.startsWith('<') && url.endsWith('>'))); finalList = finalList.concat(urls ?? []); return; diff --git a/src/app/plugins/markdown/inline/rules.ts b/src/app/plugins/markdown/inline/rules.ts index b86d139f2..bc65e9765 100644 --- a/src/app/plugins/markdown/inline/rules.ts +++ b/src/app/plugins/markdown/inline/rules.ts @@ -108,13 +108,17 @@ export const SpoilerRule: InlineMDRule = { }; const LINK_ALT = `\\[${MIN_ANY}\\]`; -const LINK_URL = `\\((<)?(https?:\\/\\/.+?)(>)?\\)`; +const LINK_URL = `\\(((<)?https?:\\/\\/.+?(>)?)\\)`; const LINK_REG_1 = new RegExp(`${LINK_ALT}${LINK_URL}`); export const LinkRule: InlineMDRule = { match: (text) => text.match(LINK_REG_1), html: (parse, match) => { - const [, g1, g2] = match; + let [, g1, g2] = match; if (!g1 || !g2) return ''; + + if (g2.startsWith('<')) g2 = g2.substring(4); + if (g2.endsWith('>')) g2 = g2.substring(0, g2.length - 4); + return `${parse(g1)}`; }, };