mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-21 09:31:17 -08:00
add more checks for paran
This commit is contained in:
1 parent
33bbec404a
commit
0eba80d43e
2 files changed
+8
-4
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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 `<a data-md href="${g2}">${parse(g1)}</a>`;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user