import { createDirectiveGenerators } from '../../../Generator/RstGenerator.ts' import { sanitizeHtml } from '../../../utils/sanitizeHtml.ts' import { jsDirectiveOptionsGenerator } from './jsDirectiveOptionsGenerator.ts' import { getParentModules } from './getParentModules.ts' import { HtmlAttributeStore } from '../../../Generator/HtmlAttributeStore.ts' import { RstGeneratorError } from '../../../Generator/RstGeneratorError.ts' export const jsDirectives = new Set([ 'js:module', 'js:function', 'js:method', 'js:class', 'js:data', 'js:attribute', ]) export const jsDirectiveGenerators = createDirectiveGenerators( [...jsDirectives], (generatorState, node) => { const directive = /js:(?\w+)/.exec(node.directive)?.groups?.directive if (!directive) { throw new RstGeneratorError(generatorState, node, 'Failed to get directive') } const attrs = new HtmlAttributeStore() attrs.append('class', 'js') attrs.append('class', directive) generatorState.writeLineHtmlTagWithAttr('dl', node, attrs, () => { generatorState.writeLineHtmlTag('dt', null, () => { const nameChain = [...getParentModules(node), node.initContentText] const url = generatorState.resolveNodeToUrl(node) generatorState.writeLine(`${sanitizeHtml(nameChain.join('.'))}`) generatorState.writeLine(``) }) generatorState.writeLineHtmlTag('dd', null, () => { generatorState.useNodeGenerator(jsDirectiveOptionsGenerator.htmlGenerator, () => { generatorState.visitNode(node.config) generatorState.visitNodes(node.children) }) }) }) }, )