mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-07 09:25:27 +00:00
feat: switch to remark from markdown-it (big)
* replaces old mentions with avatar and display name * renders things directly through React * replaces most of the markdown hacks with custom AST components * adds a tooltip to codeblock "copy to clipboard"
This commit is contained in:
@@ -1,11 +1,7 @@
|
||||
type LinkType =
|
||||
| { type: "profile"; id: string }
|
||||
| { type: "navigate"; path: string; navigation_type?: null }
|
||||
| {
|
||||
type: "navigate";
|
||||
path: string;
|
||||
navigation_type: "channel";
|
||||
channel_id: string;
|
||||
}
|
||||
| { type: "external"; href: string; url: URL }
|
||||
| { type: "none" };
|
||||
@@ -17,9 +13,6 @@ const ALLOWED_ORIGINS = [
|
||||
"local.revolt.chat",
|
||||
];
|
||||
|
||||
const CHANNEL_PATH_RE =
|
||||
/^\/server\/[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}\/channel\/[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}$/;
|
||||
|
||||
export function determineLink(href?: string): LinkType {
|
||||
let internal,
|
||||
url: URL | null = null;
|
||||
@@ -30,29 +23,12 @@ export function determineLink(href?: string): LinkType {
|
||||
|
||||
if (ALLOWED_ORIGINS.includes(url.hostname)) {
|
||||
const path = url.pathname;
|
||||
if (path.startsWith("/@")) {
|
||||
const id = path.substr(2);
|
||||
if (/[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}/.test(id)) {
|
||||
return { type: "profile", id };
|
||||
}
|
||||
} else {
|
||||
if (CHANNEL_PATH_RE.test(path)) {
|
||||
return {
|
||||
type: "navigate",
|
||||
path,
|
||||
navigation_type: "channel",
|
||||
channel_id: path.slice(43),
|
||||
};
|
||||
}
|
||||
return { type: "navigate", path };
|
||||
}
|
||||
|
||||
internal = true;
|
||||
return { type: "navigate", path };
|
||||
}
|
||||
} catch (err) {}
|
||||
|
||||
if (!internal && url) {
|
||||
if (url.protocol !== "javascript") {
|
||||
if (!url.protocol.startsWith("javascript")) {
|
||||
return { type: "external", href, url };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user