UNPKG

@mdfriday/shortcode

Version:

A flexible component-based shortcode system for Markdown content with theme support

79 lines (78 loc) 3.17 kB
import { ShortcodeMetadata, ShortcodeTemplateOptions } from "./shortcode-manager"; export declare class Shortcode { private readonly themeManager; private readonly renderer; private readonly pageRenderer; private readonly manager; constructor(); /** * Register a shortcode template dynamically * @param metadata The metadata of the shortcode * @param options Additional options for the template (funcMap, dataProvider) * @returns true if the shortcode was registered, false if it already exists */ registerShortcode(metadata: ShortcodeMetadata, options?: Partial<ShortcodeTemplateOptions>): boolean; /** * Check if a shortcode with the given ID already exists * @param id The ID of the shortcode * @returns true if the shortcode exists, false otherwise */ existsById(id: string | number): boolean; /** * Find a shortcode by its name * @param name The name of the shortcode * @returns The shortcode metadata or undefined if not found */ findByName(name: string): ShortcodeMetadata | undefined; /** * Find a shortcode by its UUID * @param uuid The UUID of the shortcode * @returns The shortcode metadata or undefined if not found */ findByUuid(uuid: string): ShortcodeMetadata | undefined; /** * Find a shortcode by its ID * @param id The ID of the shortcode * @returns The shortcode metadata or undefined if not found */ findById(id: string | number): ShortcodeMetadata | undefined; /** * Get all registered shortcodes * @returns An array of shortcode metadata */ getAllShortcodes(): ShortcodeMetadata[]; /** * Get default function map that can be used with shortcodes * @returns The default function map */ getDefaultFuncMap(): Map<string, (...args: any[]) => any>; /** * Get default data provider function * @returns A function that can be used as a data provider for shortcodes */ getDefaultDataProvider(): (params: string[], content?: string) => Record<string, any>; /** * Extract all shortcode names from markdown content * @param markdownContent The markdown content to extract shortcode names from * @returns An array of shortcode names found in the content */ extractShortcodeNames(markdownContent: string): string[]; /** * Perform a complete rendering of markdown content with shortcodes * @param markdownContent The markdown content to render * @returns The fully rendered content */ render(markdownContent: string): string; /** * First step of the rendering process - replaces shortcodes with placeholders * @param markdownContent The markdown content to process * @returns The content with shortcodes replaced by placeholders */ stepRender(markdownContent: string): string; /** * Final step of the rendering process - replaces placeholders with rendered shortcodes * @param htmlContent The HTML content with placeholders * @returns The fully rendered HTML content */ finalRender(htmlContent: string): string; }