diff --git a/index.js b/index.js index 523c5d5..dab322b 100644 --- a/index.js +++ b/index.js @@ -1,39 +1 @@ -/// -/// - -/** - * @typedef {import('mdast').Root} Root - * @typedef {import('mdast-util-directive')} DoNotTouchAsThisImportIncludesDirectivesInTree - * @typedef {import('unified').Processor} Processor - */ - -import {directiveFromMarkdown, directiveToMarkdown} from 'mdast-util-directive' -import {directive} from 'micromark-extension-directive' - -/** - * Add support for generic directives. - * - * ###### Notes - * - * Doesn’t handle the directives: create your own plugin to do that. - * - * @returns {undefined} - * Nothing. - */ -export default function remarkDirective() { - // @ts-expect-error: TS is wrong about `this`. - // eslint-disable-next-line unicorn/no-this-assignment - const self = /** @type {Processor} */ (this) - const data = self.data() - - const micromarkExtensions = - data.micromarkExtensions || (data.micromarkExtensions = []) - const fromMarkdownExtensions = - data.fromMarkdownExtensions || (data.fromMarkdownExtensions = []) - const toMarkdownExtensions = - data.toMarkdownExtensions || (data.toMarkdownExtensions = []) - - micromarkExtensions.push(directive()) - fromMarkdownExtensions.push(directiveFromMarkdown()) - toMarkdownExtensions.push(directiveToMarkdown()) -} +export {default} from './lib/index.js' diff --git a/lib/index.js b/lib/index.js new file mode 100644 index 0000000..42a6e81 --- /dev/null +++ b/lib/index.js @@ -0,0 +1,39 @@ +/// +/// +/// + +/** + * @typedef {import('mdast').Root} Root + * @typedef {import('unified').Processor} Processor + */ + +import {directiveFromMarkdown, directiveToMarkdown} from 'mdast-util-directive' +import {directive} from 'micromark-extension-directive' + +/** + * Add support for generic directives. + * + * ###### Notes + * + * Doesn’t handle the directives: create your own plugin to do that. + * + * @returns {undefined} + * Nothing. + */ +export default function remarkDirective() { + // @ts-expect-error: TS is wrong about `this`. + // eslint-disable-next-line unicorn/no-this-assignment + const self = /** @type {Processor} */ (this) + const data = self.data() + + const micromarkExtensions = + data.micromarkExtensions || (data.micromarkExtensions = []) + const fromMarkdownExtensions = + data.fromMarkdownExtensions || (data.fromMarkdownExtensions = []) + const toMarkdownExtensions = + data.toMarkdownExtensions || (data.toMarkdownExtensions = []) + + micromarkExtensions.push(directive()) + fromMarkdownExtensions.push(directiveFromMarkdown()) + toMarkdownExtensions.push(directiveToMarkdown()) +} diff --git a/package.json b/package.json index e190754..d50eaa8 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "main": "index.js", "types": "index.d.ts", "files": [ + "lib/", "index.d.ts", "index.js" ],