@mdfriday/shortcode
Version:
A flexible component-based shortcode system for Markdown content with theme support
82 lines (81 loc) • 2.88 kB
TypeScript
import { ShortcodeRenderer } from '@mdfriday/shortcode-compiler';
import { ThemeManager } from './themes';
export interface ShortcodeMetadata {
id: string | number;
uuid?: string;
slug?: string;
name: string;
template: string;
example?: string;
asset?: string;
tags?: string[];
width?: number;
height?: number;
timestamp?: number;
updated?: number;
status?: string;
namespace?: string;
hash?: string;
}
export interface ShortcodeTemplateOptions {
template: string;
funcMap?: Map<string, (...args: any[]) => any>;
dataProvider?: (params: string[], content?: string) => Record<string, any>;
}
/**
* The ShortcodeManager class provides functionality to register, manage, and query shortcodes.
*/
export declare class ShortcodeManager {
private shortcodes;
private shortcodesByUuid;
private shortcodesById;
private readonly themeManager;
constructor(themeManager: ThemeManager);
/**
* Register a shortcode template with metadata.
* @param metadata The metadata of the shortcode
* @param renderer The shortcode renderer
* @param options Additional options for the template (funcMap, dataProvider)
* @returns true if the shortcode was registered, false if it already exists
*/
registerShortcode(metadata: ShortcodeMetadata, renderer: ShortcodeRenderer, options?: Partial<ShortcodeTemplateOptions>): 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;
/**
* Check if a shortcode exists by its ID.
* @param id The ID of the shortcode
* @returns true if the shortcode exists, false otherwise
*/
existsById(id: string | number): boolean;
/**
* Get all registered shortcodes.
* @returns An array of shortcode metadata
*/
getAllShortcodes(): ShortcodeMetadata[];
/**
* Get the 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>;
/**
* Get the default function map
* @returns The default function map for use with shortcodes
*/
getDefaultFuncMap(): Map<string, (...args: any[]) => any>;
}