UNPKG

@meldscience/meld

Version:

pipeable one-shot prompt scripting toolkit

46 lines 1.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.remarkMeldDirectiveHandler = void 0; const remarkMeldDirectiveHandler = function remarkMeldDirectiveHandler() { const self = this; const data = self.data(); // Add a handler for meldDirective nodes const handle = (node) => { if (node.meldType === 'cmd' && node.data?.command) { return `@cmd[${node.data.command}]`; } else if (node.meldType === 'import' && node.data) { const { importPath, heading, importSymbol, importSymbolList } = node.data; let specifier = ''; if (heading) { specifier = ` # ${heading}`; } else if (importSymbolList) { if (importSymbolList.length === 1 && importSymbolList[0].startsWith('{')) { specifier = ` # ${importSymbolList[0]}`; } else { specifier = ` # [${importSymbolList.join(', ')}]`; } } else if (importSymbol) { specifier = ` # ${importSymbol}`; } return importPath ? `@import[${importPath}${specifier}]` : ''; } return ''; }; // Register the handler with mdast-util-to-markdown const toMarkdownExtension = { handlers: { meldDirective: handle } }; add('toMarkdownExtensions', toMarkdownExtension); function add(field, value) { const list = data[field] ? data[field] : (data[field] = []); list.push(value); } }; exports.remarkMeldDirectiveHandler = remarkMeldDirectiveHandler; //# sourceMappingURL=remarkMeldDirectiveHandler.js.map