58 lines
1.3 KiB
TypeScript
58 lines
1.3 KiB
TypeScript
export class TFile {
|
|
constructor(
|
|
public path: string,
|
|
public extension = "md",
|
|
) {}
|
|
}
|
|
|
|
export class TFolder {
|
|
constructor(public path: string) {}
|
|
}
|
|
|
|
export const notices: string[] = [];
|
|
|
|
export class Notice {
|
|
constructor(message: string) {
|
|
notices.push(message);
|
|
}
|
|
hide(): void {}
|
|
}
|
|
|
|
export class Plugin {}
|
|
export class ItemView {}
|
|
export class PluginSettingTab {}
|
|
export class Setting {}
|
|
export class Component {}
|
|
export const moment = () => undefined;
|
|
|
|
function escapeHtml(value: string): string {
|
|
return value
|
|
.replace(/&/g, "&")
|
|
.replace(/</g, "<")
|
|
.replace(/>/g, ">");
|
|
}
|
|
|
|
export const MarkdownRenderer = {
|
|
async render(
|
|
_app: unknown,
|
|
markdown: string,
|
|
el: HTMLElement,
|
|
_sourcePath: string,
|
|
_component: unknown,
|
|
): Promise<void> {
|
|
const html = escapeHtml(markdown)
|
|
.replace(
|
|
/!?\[\[([^\]|]+)(?:\|([^\]]+))?\]\]/g,
|
|
(_full, target: string, alias?: string) =>
|
|
`<a class="internal-link" href="${target}">${alias ?? target}</a>`,
|
|
)
|
|
.replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>")
|
|
.replace(
|
|
/(^|\s)(https?:\/\/[^\s]+)/g,
|
|
(_full, lead: string, url: string) =>
|
|
`${lead}<a class="external-link" href="${url}">${url}</a>`,
|
|
);
|
|
el.innerHTML = `<p>${html}</p>`;
|
|
},
|
|
};
|