add more checks for paran

This commit is contained in:
Shea Duma committed 2026-04-24 08:03:55 +03:00
1 parent 33bbec404a
commit 0eba80d43e
2 files changed
+8 -4

No files matched your search

+2 -2
View File
@@ -198,7 +198,7 @@ const elementToPlainText = (node: CustomElement, children: string): string => {
};
const SPOILERINPUTREGEX = /\|\|.+?\|\|/g;
const LINKINPUTREGEX = /<?(https?:\/\/.+?)>?( |$)/g;
const LINKINPUTREGEX = /<?(https?:\/\/.+?)>?( |$|\))/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;
+6 -2
View File
@@ -108,13 +108,17 @@ export const SpoilerRule: InlineMDRule = {
};
const LINK_ALT = `\\[${MIN_ANY}\\]`;
const LINK_URL = `\\((&lt;)?(https?:\\/\\/.+?)(&gt;)?\\)`;
const LINK_URL = `\\(((&lt;)?https?:\\/\\/.+?(&gt;)?)\\)`;
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('&lt;')) g2 = g2.substring(4);
if (g2.endsWith('&gt;')) g2 = g2.substring(0, g2.length - 4);
return `<a data-md href="${g2}">${parse(g1)}</a>`;
},
};