UNPKG

@mdx-js/language-service

Version:

MDX support for Volar

33 lines (28 loc) 806 B
/** * @import {VirtualCodePlugin} from './plugin.js' */ /** * @param {unknown} options * @returns {VirtualCodePlugin} */ export function remarkMdxFrontmatter(options) { const opts = typeof options === 'object' && options !== null ? options : {} const name = 'name' in opts ? String(opts.name) : 'frontmatter' return () => { let hasFrontmatter = false return { visit(node) { hasFrontmatter ||= node.type === 'toml' || node.type === 'yaml' }, finalize() { return ( '/** Generated by [remark-mdx-frontmatter](https://github.com/remcohaszing/remark-mdx-frontmatter) */\nexport const ' + name + ' = /** @type {' + (hasFrontmatter ? 'any' : 'undefined') + '} */ (undefined)' ) } } } }