import { marked } from 'marked';
import { escapeHtml } from './responses';
export type CustomLinkLike = {
alias: string;
content_markdown: string | null;
scope: 'public' | 'private';
};
marked.use({
renderer: {
link({ href, title, tokens }) {
const url = String(href ?? '');
if (!/^https?:\/\//i.test(url)) {
return this.parser.parseInline(tokens);
}
const safeTitle = title ? ` title="${escapeHtml(String(title))}"` : '';
return `${this.parser.parseInline(tokens)}`;
},
image({ href, title, text }) {
const src = String(href ?? '');
if (!/^https?:\/\//i.test(src)) {
return escapeHtml(String(text ?? ''));
}
const alt = escapeHtml(String(text ?? ''));
const safeTitle = title ? ` title="${escapeHtml(String(title))}"` : '';
return `
`;
},
},
walkTokens(token) {
// Neutralize raw HTML in markdown by demoting html tokens to text. Marked
// then escapes their content, so