{"name":"micromark-extension-mdx-expression","version":"1.0.4","description":"micromark extension to support MDX or MDX JS expressions","license":"MIT","keywords":["micromark","micromark-extension","mdx","mdxjs","expression","js","javascript","es","ecmascript","markdown","unified"],"repository":{"type":"git","url":"git+https://github.com/micromark/micromark-extension-mdx-expression.git#main"},"bugs":{"url":"https://github.com/micromark/micromark-extension-mdx-expression/issues"},"funding":[{"type":"GitHub Sponsors","url":"https://github.com/sponsors/unifiedjs"},{"type":"OpenCollective","url":"https://opencollective.com/unified"}],"author":{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"},"contributors":[{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"}],"sideEffects":false,"type":"module","main":"index.js","types":"dev/index.d.ts","exports":{"development":"./dev/index.js","default":"./index.js"},"dependencies":{"micromark-factory-mdx-expression":"^1.0.0","micromark-factory-space":"^1.0.0","micromark-util-character":"^1.0.0","micromark-util-events-to-acorn":"^1.0.0","micromark-util-symbol":"^1.0.0","micromark-util-types":"^1.0.0","uvu":"^0.5.0"},"scripts":{"build":"tsc --build --clean && tsc && type-coverage && micromark-build"},"xo":false,"typeCoverage":{"atLeast":100,"detail":true,"strict":true,"ignoreCatch":true},"gitHead":"88c175f9ac684efc9306e23642807657df71d6a6","homepage":"https://github.com/micromark/micromark-extension-mdx-expression/tree/main#readme","_id":"micromark-extension-mdx-expression@1.0.4","_nodeVersion":"19.3.0","_npmVersion":"9.2.0","dist":{"integrity":"sha512-TCgLxqW6ReQ3AJgtj1P0P+8ZThBTloLbeb7jNaqr6mCOLDpxUiBFE/9STgooMZttEwOQu5iEcCCa3ZSDhY9FGw==","shasum":"33fe2c6ee214738255de175a084281c11894ddda","tarball":"http://registry-npm.ywwl.com/micromark-extension-mdx-expression/download/micromark-extension-mdx-expression-1.0.4.tgz","fileCount":10,"unpackedSize":25613,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC8GWNBr77/6Aph3cNxFFNXf7801jup9OZU5JJVQB0aAwIgMCBYD2yvXBnH2QdG31vjB4Ob5b+TR8VqhhBwBseFaHU="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjzRPlACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmojog/8CekA/ALW5nHSawn0JEW0vDvPbmpuy4g417fO5pqaDwFCWxcq\r\nJpIFxGnnzaLTBLjc2tDe1swAQtQ92X2Q3s6HU1nqtgQY3DTlsDUCO29iua0u\r\nv539UpNAwnnC4fsvKepSqEhDe+a1vBVZstCj80Z/+HDPEMt4/DL9erbcoX+s\r\n9fwMEGHqUKYWnIM6ZuqZEzceeQNtMvADD5kXSe+x5PP8G+IjLukTxo6586DZ\r\nN/x1up8MR3wFam/UTi899bgy+YRCbYvRZ9Psw5+H6b4aFkIRQ1QQ2jMujUeD\r\nNDF658cAwyHnZ6jlWQZbXniZeJpgNIcGb6YNP2u7geA+911Yd5yZWCZHsgKa\r\nONd7XvAQT2C6GZw8V5E/umWmMXR/tMd8m0CPRFcBFAELi8PuAe4wYtXQEAjV\r\n51VV17l6lDN1D9MGzBcM8qbKI/QY0P7Ky+pXC+P5gDv77ZEGqcXJxYkVaPc8\r\njSYqsj7utIdElnJKAZlAJHyf++h2bkaqLbpCvO2IwLLv0XcwVOubp6yFsH2J\r\nOOcjjLgNyIxb0yF/GGviv7wPMcpYJCKopUwzAZd9k/sqRSvxT32b4zM9xi13\r\ncs8JoRGFKDL91CMcSRUDhHXeQknxqKo3c4h8L+mMNEI6+4NAL+2f/z/CCZ1n\r\n5XhIonOmSUBFT3hqXa0dSo3u+JtO+/kzTYk=\r\n=NVOf\r\n-----END PGP SIGNATURE-----\r\n","size":6191,"noattachment":false,"key":"/micromark-extension-mdx-expression/-/micromark-extension-mdx-expression-1.0.4.tgz"},"_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"directories":{},"maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/micromark-extension-mdx-expression_1.0.4_1674384357115_0.021777739442156108"},"_hasShrinkwrap":false,"readme":"# micromark-extension-mdx-expression\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n[![Size][size-badge]][size]\n[![Sponsors][sponsors-badge]][collective]\n[![Backers][backers-badge]][collective]\n[![Chat][chat-badge]][chat]\n\n[micromark][] extension to support [MDX][mdxjs] expressions (`{Math.PI}`).\n\n## Contents\n\n*   [What is this?](#what-is-this)\n*   [When to use this](#when-to-use-this)\n*   [Install](#install)\n*   [Use](#use)\n*   [API](#api)\n    *   [`mdxExpression(options?)`](#mdxexpressionoptions)\n    *   [Options](#options)\n*   [Authoring](#authoring)\n*   [Syntax](#syntax)\n*   [Errors](#errors)\n    *   [Unexpected end of file in expression, expected a corresponding closing brace for `{`](#unexpected-end-of-file-in-expression-expected-a-corresponding-closing-brace-for-)\n    *   [Unexpected lazy line in expression in container, expected line to be prefixed…](#unexpected-lazy-line-in-expression-in-container-expected-line-to-be-prefixed)\n    *   [Unexpected `$type` in code: expected an object spread (`{...spread}`)](#unexpected-type-in-code-expected-an-object-spread-spread)\n    *   [Unexpected extra content in spread: only a single spread is supported](#unexpected-extra-content-in-spread-only-a-single-spread-is-supported)\n    *   [Could not parse expression with acorn](#could-not-parse-expression-with-acorn)\n*   [Tokens](#tokens)\n*   [Types](#types)\n*   [Compatibility](#compatibility)\n*   [Security](#security)\n*   [Related](#related)\n*   [Contribute](#contribute)\n*   [License](#license)\n\n## What is this?\n\nThis package contains an extension that adds support for the expression syntax\nenabled by [MDX][mdxjs] to [`micromark`][micromark].\nThese extensions are used inside MDX.\n\nThis package can be made aware or unaware of JavaScript syntax.\nWhen unaware, expressions could include Rust or variables or whatnot.\n\n## When to use this\n\nThis project is useful when you want to support expressions in markdown.\n\nYou can use this extension when you are working with [`micromark`][micromark].\nTo support all MDX features, use\n[`micromark-extension-mdxjs`][micromark-extension-mdxjs] instead.\n\nWhen you need a syntax tree, combine this package with\n[`mdast-util-mdx-expression`][mdast-util-mdx-expression].\n\nAll these packages are used in [`remark-mdx`][remark-mdx], which focusses on\nmaking it easier to transform content by abstracting these internals away.\n\nWhen you are using [`mdx-js/mdx`][mdxjs], all of this is already included.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install micromark-extension-mdx-expression\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {mdxExpression} from 'https://esm.sh/micromark-extension-mdx-expression@2'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n<script type=\"module\">\n  import {mdxExpression} from 'https://esm.sh/micromark-extension-mdx-expression@2?bundle'\n</script>\n```\n\n## Use\n\n```js\nimport {Parser} from 'acorn'\nimport acornJsx from 'acorn-jsx'\nimport {micromark} from 'micromark'\nimport {mdxExpression} from 'micromark-extension-mdx-expression'\n\n// Unaware of JavaScript (“agnostic”) (balanced braces):\nconst output = micromark('a {1 + 1} b', {extensions: [mdxExpression()]})\n\nconsole.log(output)\n\n// Aware of JavaScript:\nmicromark('a {!} b', {extensions: [mdxExpression({acorn: Parser.extend(acornJsx())})]})\n```\n\nYields:\n\n```html\n<p>a  b</p>\n```\n\n```txt\n[1:5: Could not parse expression with acorn] {\n  ancestors: undefined,\n  cause: SyntaxError: Unexpected token\n      at pp$4.raise (file:///Users/tilde/Projects/oss/micromark-extension-mdx-expression/node_modules/acorn/dist/acorn.mjs:3547:13)\n      at pp$9.unexpected (file:///Users/tilde/Projects/oss/micromark-extension-mdx-expression/node_modules/acorn/dist/acorn.mjs:758:8)\n      …\n    pos: 4,\n    loc: { line: 1, column: 4 },\n    raisedAt: 1\n  },\n  column: 5,\n  fatal: undefined,\n  line: 1,\n  place: { line: 1, column: 5, offset: 4 },\n  reason: 'Could not parse expression with acorn',\n  ruleId: 'acorn',\n  source: 'micromark-extension-mdx-expression',\n  url: 'https://github.com/micromark/micromark-extension-mdx-expression/tree/main/packages/micromark-extension-mdx-expression#could-not-parse-expression-with-acorn'\n}\n```\n\n…which is useless: go to a syntax tree with\n[`mdast-util-from-markdown`][mdast-util-from-markdown] and\n[`mdast-util-mdx-expression`][mdast-util-mdx-expression] instead.\n\n## API\n\nThis package exports the identifier [`mdxExpression`][api-mdx-expression].\nThere is no default export.\n\nThe export map supports the [`development` condition][development].\nRun `node --conditions development module.js` to get instrumented dev code.\nWithout this condition, production code is loaded.\n\n### `mdxExpression(options?)`\n\nCreate an extension for `micromark` to enable MDX expression syntax.\n\n###### Parameters\n\n*   `options` ([`Options`][api-options], optional)\n    — configuration\n\n###### Returns\n\nExtension for `micromark` that can be passed in `extensions` to enable MDX\nexpression syntax ([`Extension`][micromark-extension]).\n\n### Options\n\nConfiguration (TypeScript type).\n\n###### Fields\n\n*   `acorn` ([`Acorn`][acorn], optional)\n    — acorn parser to use\n*   `acornOptions` ([`AcornOptions`][acorn-options], default:\n    `{ecmaVersion: 2024, locations: true, sourceType: 'module'}`)\n    — configuration for acorn; all fields except `locations` can be set\n*   `addResult` (`boolean`, default: `false`)\n    — whether to add `estree` fields to tokens with results from acorn\n\n<!-- Note: `spread` and `allowEmpty` are intentionally not documented. -->\n\n## Authoring\n\nWhen authoring markdown with JavaScript, keep in mind that MDX is a whitespace\nsensitive and line-based language, while JavaScript is insensitive to\nwhitespace.\nThis affects how markdown and JavaScript interleave with eachother in MDX.\nFor more info on how it works, see [§ Interleaving][mdxjs-interleaving] on the\nMDX site.\n\n## Syntax\n\nThis extension supports MDX both aware and unaware to JavaScript (respectively\ngnostic and agnostic).\nDepending on whether acorn is passed, either valid JavaScript must be used in\nexpressions, or arbitrary text (such as Rust code or so) can be used.\n\nThere are two types of expressions: in text (inline, span) or in flow (block).\nThey start with `{`.\n\nDepending on whether `acorn` is passed, expressions are either parsed in several\ntries until whole JavaScript is found (as in, nested curly braces depend on JS\nexpression nesting), or they are counted and must be balanced.\n\nExpressions end with `}`.\n\nFor flow (block) expressions, optionally markdown spaces (` ` or `\\t`) can occur\nafter the closing brace, and finally a markdown line ending (`\\r`, `\\n`) or the\nend of the file must follow.\n\nWhile markdown typically knows no errors, for MDX it is decided to instead\nthrow on invalid syntax.\n\n```mdx\nHere is an expression in a heading:\n\n## Hello, {1 + 1}!\n\nIn agnostic mode, balanced braces can occur: {a + {b} + c}.\n\nIn gnostic mode, the value of the expression must be JavaScript, so\nthis would fail: {!}.\nBut, in gnostic mode, braces can be in comments, strings, or in other\nplaces: {1 /* { */ + 2}.\n\nThe previous examples were text (inline, span) expressions, they can\nalso be flow (block):\n\n{\n  1 + 1\n}\n\nThis is incorrect, because there are further characters:\n\n{\n  1 + 1\n}!\n```\n\n```mdx-broken\nBlank lines cannot occur in text, because markdown has already split them in\nseparate constructs, so this is incorrect: {1 +\n\n1}\n```\n\n```mdx\nIn flow, you can have blank lines:\n\n{\n  1 +\n\n  2\n}\n```\n\n## Errors\n\n### Unexpected end of file in expression, expected a corresponding closing brace for `{`\n\nThis error occurs if a `{` was seen without a `}` (source:\n`micromark-extension-mdx-expression`, rule id: `unexpected-eof`).\nFor example:\n\n```mdx-broken\na { b\n```\n\n### Unexpected lazy line in expression in container, expected line to be prefixed…\n\nThis error occurs if a `{` was seen in a container which then has lazy content\n(source: `micromark-extension-mdx-expression`, rule id: `unexpected-lazy`).\nFor example:\n\n```mdx-broken\n> {a\nb}\n```\n\n### Unexpected `$type` in code: expected an object spread (`{...spread}`)\n\nThis error occurs if a spread was expected but something else was found\n(source: `micromark-extension-mdx-expression`, rule id: `non-spread`).\nFor example:\n\n```mdx-broken\n<a {b=c}={} d>\n```\n\n### Unexpected extra content in spread: only a single spread is supported\n\nThis error occurs if a spread was expected but more was found after it\n(source: `micromark-extension-mdx-expression`, rule id: `spread-extra`).\nFor example:\n\n```mdx-broken\n<a {...b,c} d>\n```\n\n### Could not parse expression with acorn\n\nThis error occurs if acorn crashes or when there is more content after a JS\nexpression (source: `micromark-extension-mdx-expression`, rule id: `acorn`).\nFor example:\n\n```mdx-broken\na {\"b\" \"c\"} d\n```\n\n```mdx-broken\na {var b = \"c\"} d\n```\n\n## Tokens\n\nTwo tokens are used, `mdxFlowExpression` and `mdxTextExpression`, to reflect\nflow and text expressions.\n\nThey include:\n\n*   `lineEnding` for the markdown line endings `\\r`, `\\n`, and `\\r\\n`\n*   `mdxFlowExpressionMarker` and `mdxTextExpressionMarker` for the braces\n*   `whitespace` for markdown spaces and tabs in blank lines\n*   `mdxFlowExpressionChunk` and `mdxTextExpressionChunk` for chunks of\n    expression content\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional type [`Options`][api-options].\n\n## Compatibility\n\nProjects maintained by the unified collective are compatible with maintained\nversions of Node.js.\n\nWhen we cut a new major release, we drop support for unmaintained versions of\nNode.\nThis means we try to keep the current release line,\n`micromark-extension-mdx-expression@^2`, compatible with Node.js 16.\n\nThis package works with `micromark` version `3` and later.\n\n## Security\n\nThis package is safe.\n\n## Related\n\n*   [`micromark-extension-mdxjs`][micromark-extension-mdxjs]\n    — support all MDX syntax\n*   [`mdast-util-mdx-expression`][mdast-util-mdx-expression]\n    — support MDX expressions in mdast\n*   [`remark-mdx`][remark-mdx]\n    — support all MDX syntax in remark\n\n## Contribute\n\nSee [`contributing.md` in `micromark/.github`][contributing] for ways to get\nstarted.\nSee [`support.md`][support] for ways to get help.\n\nThis project has a [code of conduct][coc].\nBy interacting with this repository, organization, or community you agree to\nabide by its terms.\n\n## License\n\n[MIT][license] © [Titus Wormer][author]\n\n<!-- Definitions -->\n\n[build-badge]: https://github.com/micromark/micromark-extension-mdx-expression/workflows/main/badge.svg\n\n[build]: https://github.com/micromark/micromark-extension-mdx-expression/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark-extension-mdx-expression.svg\n\n[coverage]: https://codecov.io/github/micromark/micromark-extension-mdx-expression\n\n[downloads-badge]: https://img.shields.io/npm/dm/micromark-extension-mdx-expression.svg\n\n[downloads]: https://www.npmjs.com/package/micromark-extension-mdx-expression\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=micromark-extension-mdx-expression\n\n[size]: https://bundlejs.com/?q=micromark-extension-mdx-expression\n\n[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg\n\n[backers-badge]: https://opencollective.com/unified/backers/badge.svg\n\n[collective]: https://opencollective.com/unified\n\n[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg\n\n[chat]: https://github.com/micromark/micromark/discussions\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[esmsh]: https://esm.sh\n\n[license]: https://github.com/micromark/micromark-extension-mdx-expression/blob/main/license\n\n[author]: https://wooorm.com\n\n[contributing]: https://github.com/micromark/.github/blob/main/contributing.md\n\n[support]: https://github.com/micromark/.github/blob/main/support.md\n\n[coc]: https://github.com/micromark/.github/blob/main/code-of-conduct.md\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[typescript]: https://www.typescriptlang.org\n\n[development]: https://nodejs.org/api/packages.html#packages_resolving_user_conditions\n\n[micromark]: https://github.com/micromark/micromark\n\n[micromark-extension]: https://github.com/micromark/micromark#syntaxextension\n\n[micromark-extension-mdxjs]: https://github.com/micromark/micromark-extension-mdxjs\n\n[mdast-util-mdx-expression]: https://github.com/syntax-tree/mdast-util-mdx-expression\n\n[mdast-util-from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown\n\n[remark-mdx]: https://mdxjs.com/packages/remark-mdx/\n\n[mdxjs]: https://mdxjs.com\n\n[mdxjs-interleaving]: https://mdxjs.com/docs/what-is-mdx/#interleaving\n\n[acorn]: https://github.com/acornjs/acorn\n\n[acorn-options]: https://github.com/acornjs/acorn/blob/96c721dbf89d0ccc3a8c7f39e69ef2a6a3c04dfa/acorn/dist/acorn.d.ts#L16\n\n[api-mdx-expression]: #mdxexpressionoptions\n\n[api-options]: #options\n","publish_time":1674384357279,"_cnpm_publish_time":1674384357279,"dist-tags":{"latest":"3.0.1","next":"1.0.0-alpha.1"}}