UNPKG

@entro314labs/starlight-document-converter

Version:

A comprehensive document converter for Astro Starlight that transforms various document formats into Starlight-compatible Markdown with proper frontmatter

126 lines (125 loc) 3.72 kB
// src/plugins/registry.ts var DefaultPluginRegistry = class { processors = /* @__PURE__ */ new Map(); enhancers = []; validators = []; /** * Register a file processor plugin */ registerProcessor(processor) { const key = `${processor.metadata.name}@${processor.metadata.version}`; this.validateProcessor(processor); this.processors.set(key, processor); console.log(`Registered processor: ${processor.metadata.name} v${processor.metadata.version}`); } /** * Register a metadata enhancer plugin */ registerEnhancer(enhancer) { this.validateEnhancer(enhancer); this.enhancers.push(enhancer); this.enhancers.sort((a, b) => (b.priority || 0) - (a.priority || 0)); console.log(`Registered enhancer: ${enhancer.metadata.name} v${enhancer.metadata.version}`); } /** * Register a quality validator plugin */ registerValidator(validator) { this.validateValidator(validator); this.validators.push(validator); console.log(`Registered validator: ${validator.metadata.name} v${validator.metadata.version}`); } /** * Get all registered processors */ getProcessors() { return Array.from(this.processors.values()); } /** * Get processors that can handle a specific file extension */ getProcessorsForExtension(extension) { return this.getProcessors().filter( (processor) => processor.extensions.includes(extension.toLowerCase()) ); } /** * Get all registered enhancers (sorted by priority) */ getEnhancers() { return [...this.enhancers]; } /** * Get all registered validators */ getValidators() { return [...this.validators]; } /** * Clear all registered plugins */ clear() { this.processors.clear(); this.enhancers.length = 0; this.validators.length = 0; } /** * Get plugin statistics */ getStats() { const processorExtensions = /* @__PURE__ */ new Set(); this.getProcessors().forEach((p) => { p.extensions.forEach((ext) => { processorExtensions.add(ext); }); }); return { processors: this.processors.size, enhancers: this.enhancers.length, validators: this.validators.length, supportedExtensions: Array.from(processorExtensions) }; } validateProcessor(processor) { if (!processor.metadata?.name) { throw new Error("Processor must have a name in metadata"); } if (!processor.metadata?.version) { throw new Error("Processor must have a version in metadata"); } if (!processor.extensions || processor.extensions.length === 0) { throw new Error("Processor must specify at least one file extension"); } if (typeof processor.process !== "function") { throw new Error("Processor must have a process function"); } } validateEnhancer(enhancer) { if (!enhancer.metadata?.name) { throw new Error("Enhancer must have a name in metadata"); } if (!enhancer.metadata?.version) { throw new Error("Enhancer must have a version in metadata"); } if (typeof enhancer.enhance !== "function") { throw new Error("Enhancer must have an enhance function"); } } validateValidator(validator) { if (!validator.metadata?.name) { throw new Error("Validator must have a name in metadata"); } if (!validator.metadata?.version) { throw new Error("Validator must have a version in metadata"); } if (typeof validator.validate !== "function") { throw new Error("Validator must have a validate function"); } } }; var pluginRegistry = new DefaultPluginRegistry(); export { DefaultPluginRegistry, pluginRegistry }; //# sourceMappingURL=chunk-MMSVNVDP.js.map