mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-20 09:01:17 -08:00
add stripping in plaintext
This commit is contained in:
1 parent
372504a82e
commit
c2ac2c78bb
2 files changed
+8
-5
No files matched your search
@@ -198,8 +198,7 @@ const elementToPlainText = (node: CustomElement, children: string): string => {
|
||||
};
|
||||
|
||||
const SPOILERINPUTREGEX = /\|\|.+?\|\|/g;
|
||||
const HTTP_URL_PATTERN = `<?https?:\\/\\/(?:www\\.)?(?:[^\\s)]*)(?<![.,:;!/?()[\\]\\s]+)>?`;
|
||||
const URL_REG = new RegExp(HTTP_URL_PATTERN, 'g');
|
||||
const LINKINPUTREGEX = /<?(https?:\/\/.+?)>?( |$)/g;
|
||||
|
||||
/**
|
||||
* convert slate internal representation to a plain text string that can be sent to the server
|
||||
@@ -220,6 +219,9 @@ export const toPlainText = (
|
||||
if (Text.isText(node)) {
|
||||
let { text } = node;
|
||||
text = text.replaceAll(SPOILERINPUTREGEX, '[Spoiler]');
|
||||
text = text.replace(LINKINPUTREGEX, '$1$2');
|
||||
// oxlint-disable-next-line no-console
|
||||
console.log(text.match(LINKINPUTREGEX), text);
|
||||
|
||||
if (stripNickname && nickNameReplacement) {
|
||||
nickNameReplacement?.keys().forEach((key) => {
|
||||
@@ -320,7 +322,7 @@ export const getMentions = (mx: MatrixClient, roomId: string, editor: Editor): M
|
||||
* @returns the mentions in a message {@link MentionsData}
|
||||
*/
|
||||
export const getLinks = (plaintext: string): string[] | undefined => {
|
||||
const urlsMatch = plaintext.match(URL_REG);
|
||||
const urlsMatch = plaintext.match(LINKINPUTREGEX);
|
||||
let urls = urlsMatch ? [...new Set(urlsMatch)] : undefined;
|
||||
urls = urls?.filter((url) => !(url.startsWith('<') && url.endsWith('>')));
|
||||
|
||||
|
||||
@@ -149,10 +149,11 @@ export function MText({
|
||||
const urlsMatch = trimmedBody.match(URL_REG);
|
||||
let urls = urlsMatch ? [...new Set(urlsMatch)] : undefined;
|
||||
bundleContent = content['com.beeper.linkpreviews'] as BundleContent[];
|
||||
if(bundleContent?.length > 0){
|
||||
//small "fix" for if someone sends malformed objects (ie not arrays of objects)
|
||||
try{
|
||||
bundleContent = bundleContent?.filter((bundle) => !!urls?.includes(bundle.matched_url));
|
||||
if (renderUrlsPreview && bundleContent) urls = bundleContent.map((bundle) => bundle.matched_url);
|
||||
}
|
||||
}catch{ urls = [];};
|
||||
|
||||
if ((content['com.beeper.per_message_profile'] as PerMessageProfileBeeperFormat)?.has_fallback) {
|
||||
// unwrap per-message profile fallback if present
|
||||
|
||||
Reference in new issue
Block a user