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:
Paul Makles
2022-07-08 14:24:48 +01:00
parent a766183f01
commit 34bb2bbc13
17 changed files with 1815 additions and 623 deletions

View File

@@ -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 };
}
}