some changes
This commit is contained in:
+24
-7
@@ -13,10 +13,25 @@ function escapeHtml(value) {
|
||||
return String(value).replace(/[&<>"']/g, c => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c]));
|
||||
}
|
||||
|
||||
const emoji = EMOJI_SHORTCODES;
|
||||
let markdownFiles = new Map();
|
||||
let markdownFileRoutes = new Map();
|
||||
|
||||
function attachmentRoute(value) {
|
||||
try {
|
||||
const path = new URL(String(value || ""), location.origin).pathname;
|
||||
return /^\/f\/[^/]+\/[^/]+$/.test(path) ? path : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function safeUrl(value) {
|
||||
const raw = String(value || "").trim();
|
||||
let raw = String(value || "").trim();
|
||||
if (!raw || raw.startsWith("//")) return "#";
|
||||
if (raw.startsWith("#")) return escapeHtml(raw);
|
||||
const route = attachmentRoute(raw);
|
||||
if (route && markdownFileRoutes.has(route)) raw = markdownFileRoutes.get(route);
|
||||
try {
|
||||
const url = new URL(raw, location.origin);
|
||||
if (url.protocol === "mailto:") return escapeHtml(url.href);
|
||||
@@ -27,16 +42,18 @@ function safeUrl(value) {
|
||||
}
|
||||
}
|
||||
|
||||
const emoji = EMOJI_SHORTCODES;
|
||||
let markdownFiles = new Map();
|
||||
|
||||
export function setMarkdownFiles(files) {
|
||||
markdownFiles = new Map((Array.isArray(files) ? files : [])
|
||||
const normalized = (Array.isArray(files) ? files : [])
|
||||
.filter(file => file && file.filename && file.url)
|
||||
.map(file => [String(file.filename), {
|
||||
.map(file => ({
|
||||
filename: String(file.filename),
|
||||
url: String(file.url),
|
||||
mimeType: String(file.mime_type || ""),
|
||||
}]));
|
||||
}));
|
||||
markdownFiles = new Map(normalized.map(file => [file.filename, file]));
|
||||
markdownFileRoutes = new Map(normalized
|
||||
.map(file => [attachmentRoute(file.url), file.url])
|
||||
.filter(([route]) => route));
|
||||
}
|
||||
|
||||
export function unresolvedMarkdownFileAliases(value) {
|
||||
|
||||
Reference in New Issue
Block a user