obsidian-dev-utils
Version:
This is the collection of useful functions that you can use for your Obsidian plugin development
80 lines (79 loc) • 2.67 kB
text/typescript
/**
* @packageDocumentation
*
* This module provides utility functions for processing Markdown content in Obsidian.
*/
import type { App } from 'obsidian';
import { Component } from 'obsidian';
import type { PathOrAbstractFile } from './FileSystem.mjs';
/**
* The options for the full render.
*/
export interface FullRenderOptions {
/**
* The Obsidian app instance.
*/
app: App;
/**
* The Component instance to use for the render.
*/
component?: Component;
/**
* The HTMLElement to render to.
*/
el: HTMLElement;
/**
* The Markdown string to render.
*/
markdown: string;
/**
* Whether to register link handlers for the rendered element.
*/
shouldRegisterLinkHandlers?: boolean;
/**
* The source path to resolve relative links.
*/
sourcePath?: string;
}
/**
* Render the markdown and embeds.
*
* @param options - The options for the full render.
* @returns The {@link Promise} that resolves when the full render is complete.
*/
export declare function fullRender(options: FullRenderOptions): Promise<void>;
/**
* Converts Markdown to HTML.
*
* @param app - The Obsidian app instance.
* @param markdown - The Markdown string to convert.
* @param sourcePath - (optional) The source path to resolve relative links.
* @returns The HTML string.
*/
export declare function markdownToHtml(app: App, markdown: string, sourcePath?: string): Promise<string>;
/**
* Registers link handlers for the given element.
*
* @param app - The Obsidian app instance.
* @param el - The HTMLElement to register link handlers for.
* @param sourcePath - The source path to resolve relative links from.
*/
export declare function registerLinkHandlers(app: App, el: HTMLElement, sourcePath?: string): Promise<void>;
/**
* Renders an external link.
*
* @param app - The Obsidian app instance.
* @param url - The URL to render the external link for.
* @param displayText - The text to display for the external link.
* @returns The HTMLAnchorElement containing the rendered external link.
*/
export declare function renderExternalLink(app: App, url: string, displayText?: string): Promise<HTMLAnchorElement>;
/**
* Renders an internal link.
*
* @param app - The Obsidian app instance.
* @param pathOrAbstractFile - The path or abstract file to render the internal link for.
* @param displayText - The text to display for the internal link.
* @returns The HTMLAnchorElement containing the rendered internal link.
*/
export declare function renderInternalLink(app: App, pathOrAbstractFile: PathOrAbstractFile, displayText?: string): Promise<HTMLAnchorElement>;