├── .husky ├── .gitignore └── pre-commit ├── .npmrc ├── .vercelignore ├── docs ├── packages │ ├── mdx.server.md │ ├── vue.server.md │ ├── esbuild.server.md │ ├── loader.server.md │ ├── preact.server.md │ ├── react.server.md │ ├── rollup.server.md │ ├── register.server.md │ ├── node-loader.server.md │ ├── remark-mdx.server.md │ └── index.server.mdx ├── _static │ ├── og.png │ ├── og-v2.png │ ├── favicon.ico │ └── icon.svg ├── _component │ ├── note.server.js │ ├── snowfall.server.js │ ├── home.server.js │ ├── icon │ │ ├── twitter.server.js │ │ ├── mdx.server.js │ │ ├── open-collective.server.js │ │ └── github.server.js │ ├── sort.js │ ├── foot-site.server.js │ ├── nav-site.server.js │ ├── copy.client.js │ ├── nav.server.js │ └── blog.server.js ├── 404.server.mdx ├── _asset │ ├── index.client.js │ └── root.client.js ├── guides │ ├── index.server.mdx │ ├── frontmatter.server.mdx │ ├── math.server.mdx │ ├── mdx-on-demand.server.mdx │ ├── gfm.server.mdx │ └── embed.server.mdx ├── community │ ├── index.server.mdx │ ├── projects.server.mdx │ ├── support.server.mdx │ ├── sponsor.server.mdx │ └── contribute.server.mdx ├── blog │ ├── index.server.mdx │ ├── shortcodes.server.mdx │ └── conf.server.mdx ├── docs │ └── index.server.mdx ├── playground.server.mdx ├── migrating │ └── v1.server.mdx ├── _config.js └── index.server.mdx ├── packages ├── esbuild │ ├── test │ │ └── files │ │ │ ├── md-file.md │ │ │ ├── mdx-file-importing-markdown.mdx │ │ │ └── components.js │ ├── tsconfig.json │ ├── index.js │ ├── license │ └── package.json ├── mdx │ ├── lib │ │ ├── condition.browser.js │ │ ├── condition.js │ │ ├── util │ │ │ ├── extnames.js │ │ │ ├── extnames-to-regex.js │ │ │ ├── estree-util-is-declaration.js │ │ │ ├── estree-util-to-binary-addition.js │ │ │ ├── estree-util-create.js │ │ │ ├── estree-util-declaration-to-expression.js │ │ │ ├── resolve-file-and-options.js │ │ │ ├── resolve-evaluate-options.js │ │ │ ├── create-format-aware-processors.js │ │ │ ├── estree-util-specifiers-to-declarations.js │ │ │ └── estree-util-to-id-or-member-expression.js │ │ ├── node-types.js │ │ ├── plugin │ │ │ ├── rehype-recma.js │ │ │ ├── rehype-remove-raw.js │ │ │ ├── recma-stringify.js │ │ │ ├── recma-jsx-build.js │ │ │ └── remark-mark-and-unravel.js │ │ ├── run.js │ │ ├── evaluate.js │ │ ├── compile.js │ │ └── core.js │ ├── tsconfig.json │ ├── test │ │ └── context │ │ │ ├── data.js │ │ │ └── components.js │ ├── index.js │ ├── license │ └── package.json ├── vue │ ├── index.js │ ├── tsconfig.json │ ├── lib │ │ └── index.js │ ├── license │ ├── package.json │ └── test │ │ └── test.js ├── remark-mdx │ ├── tsconfig.json │ ├── license │ ├── index.js │ └── package.json ├── loader │ ├── tsconfig.json │ ├── index.cjs │ ├── index.d.ts │ ├── license │ ├── package.json │ └── lib │ │ └── index.js ├── rollup │ ├── tsconfig.json │ ├── index.js │ ├── license │ ├── lib │ │ └── index.js │ ├── test │ │ └── index.test.js │ └── package.json ├── node-loader │ ├── tsconfig.json │ ├── test │ │ ├── react-18-node-loader.js │ │ └── index.test.js │ ├── index.js │ ├── license │ ├── package.json │ └── lib │ │ └── index.js ├── preact │ ├── tsconfig.json │ ├── index.js │ ├── license │ ├── package.json │ ├── lib │ │ └── index.js │ └── test │ │ └── test.jsx ├── react │ ├── tsconfig.json │ ├── index.js │ ├── license │ ├── package.json │ ├── lib │ │ └── index.js │ └── test │ │ └── test.jsx └── register │ ├── tsconfig.json │ ├── index.cjs │ ├── test │ └── index.test.cjs │ ├── license │ ├── package.json │ ├── lib │ └── index.cjs │ └── readme.md ├── .prettierignore ├── changelog.md ├── babel.config.cjs ├── .editorconfig ├── website ├── loader-react-server.js ├── loader.js ├── schema-description.js ├── bundle.js └── prep.js ├── tsconfig.json ├── renovate.json5 ├── .gitignore ├── license ├── .github └── workflows │ └── main.yml ├── script └── jsx-loader.js └── patches ├── react-server-dom-webpack+0.0.0-experimental-1159ff619-20220324.patch └── react-server-dom-webpack+0.0.0-experimental-1159ff619-20220324.patch.bak /.husky/.gitignore: -------------------------------------------------------------------------------- 1 | _ 2 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | legacy-peer-deps=true 2 | -------------------------------------------------------------------------------- /.vercelignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /docs/packages/mdx.server.md: -------------------------------------------------------------------------------- 1 | ../../packages/mdx/readme.md -------------------------------------------------------------------------------- /docs/packages/vue.server.md: -------------------------------------------------------------------------------- 1 | ../../packages/vue/readme.md -------------------------------------------------------------------------------- /packages/esbuild/test/files/md-file.md: -------------------------------------------------------------------------------- 1 | Some content. 2 | -------------------------------------------------------------------------------- /docs/packages/esbuild.server.md: -------------------------------------------------------------------------------- 1 | ../../packages/esbuild/readme.md -------------------------------------------------------------------------------- /docs/packages/loader.server.md: -------------------------------------------------------------------------------- 1 | ../../packages/loader/readme.md -------------------------------------------------------------------------------- /docs/packages/preact.server.md: -------------------------------------------------------------------------------- 1 | ../../packages/preact/readme.md -------------------------------------------------------------------------------- /docs/packages/react.server.md: -------------------------------------------------------------------------------- 1 | ../../packages/react/readme.md -------------------------------------------------------------------------------- /docs/packages/rollup.server.md: -------------------------------------------------------------------------------- 1 | ../../packages/rollup/readme.md -------------------------------------------------------------------------------- /docs/packages/register.server.md: -------------------------------------------------------------------------------- 1 | ../../packages/register/readme.md -------------------------------------------------------------------------------- /docs/packages/node-loader.server.md: -------------------------------------------------------------------------------- 1 | ../../packages/node-loader/readme.md -------------------------------------------------------------------------------- /docs/packages/remark-mdx.server.md: -------------------------------------------------------------------------------- 1 | ../../packages/remark-mdx/readme.md -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | coverage/ 3 | public/ 4 | *.md 5 | *.mdx 6 | -------------------------------------------------------------------------------- /packages/mdx/lib/condition.browser.js: -------------------------------------------------------------------------------- 1 | export const development = false 2 | -------------------------------------------------------------------------------- /docs/_static/og.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BuilderIO/mdx/main/docs/_static/og.png -------------------------------------------------------------------------------- /packages/vue/index.js: -------------------------------------------------------------------------------- 1 | export {MDXProvider, useMDXComponents} from './lib/index.js' 2 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | npx lint-staged 5 | -------------------------------------------------------------------------------- /docs/_static/og-v2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BuilderIO/mdx/main/docs/_static/og-v2.png -------------------------------------------------------------------------------- /docs/_static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BuilderIO/mdx/main/docs/_static/favicon.ico -------------------------------------------------------------------------------- /packages/remark-mdx/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "include": ["test/**/*.js", "*.js"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/loader/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "include": ["lib/**/*.js", "test/**/*.js"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/mdx/lib/condition.js: -------------------------------------------------------------------------------- 1 | import process from 'process' 2 | 3 | export const development = process.env.NODE_ENV === 'development' 4 | -------------------------------------------------------------------------------- /packages/mdx/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "include": ["lib/**/*.js", "test/**/*.js", "*.js"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/rollup/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "include": ["lib/**/*.js", "test/**/*.js", "*.js"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/esbuild/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "include": ["lib/**/*.js", "test/**/*.js", "index.js"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/node-loader/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "include": ["lib/**/*.js", "test/**/*.js", "*.js"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/preact/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "include": ["lib/**/*.js", "test/**/*.js", "index.js"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/react/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "include": ["lib/**/*.js", "test/**/*.js", "index.js"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/register/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "include": ["lib/**/*.cjs", "test/**/*.cjs", "*.cjs"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/vue/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "include": ["lib/**/*.js", "test/**/*.js", "index.js"] 4 | } 5 | -------------------------------------------------------------------------------- /changelog.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | See [GitHub Releases][releases] for the changelog. 4 | 5 | [releases]: https://github.com/mdx-js/mdx/releases 6 | -------------------------------------------------------------------------------- /packages/preact/index.js: -------------------------------------------------------------------------------- 1 | export { 2 | MDXContext, 3 | MDXProvider, 4 | useMDXComponents, 5 | withMDXComponents 6 | } from './lib/index.js' 7 | -------------------------------------------------------------------------------- /packages/react/index.js: -------------------------------------------------------------------------------- 1 | export { 2 | MDXContext, 3 | MDXProvider, 4 | useMDXComponents, 5 | withMDXComponents 6 | } from './lib/index.js' 7 | -------------------------------------------------------------------------------- /packages/rollup/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @typedef {import('./lib/index.js').Options} Options 3 | */ 4 | 5 | export {rollup as default} from './lib/index.js' 6 | -------------------------------------------------------------------------------- /babel.config.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | babelrcRoots: ['.', './docs', './packages/*'], 3 | presets: [['@babel/preset-react', {runtime: 'automatic'}]] 4 | } 5 | -------------------------------------------------------------------------------- /packages/esbuild/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @typedef {import('./lib/index.js').Options} Options 3 | */ 4 | 5 | export {esbuild as default} from './lib/index.js' 6 | -------------------------------------------------------------------------------- /packages/register/index.cjs: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const runtime = require('react/jsx-runtime') 4 | const register = require('./lib/index.cjs') 5 | 6 | register({...runtime}) 7 | -------------------------------------------------------------------------------- /packages/mdx/test/context/data.js: -------------------------------------------------------------------------------- 1 | export const number = 3.14 2 | 3 | export const object = {a: 1, b: 2} 4 | 5 | export const array = [1, 2] 6 | 7 | export default 2 * number 8 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_size = 2 7 | indent_style = space 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /packages/esbuild/test/files/mdx-file-importing-markdown.mdx: -------------------------------------------------------------------------------- 1 | import {Pill} from './components.js' 2 | import Content from './md-file.md' 3 | 4 | # heading 5 | 6 | A little pill. 7 | 8 | 9 | -------------------------------------------------------------------------------- /website/loader-react-server.js: -------------------------------------------------------------------------------- 1 | import * as serverDomWebpack from 'react-server-dom-webpack/node-loader' 2 | import base from './loader.js' 3 | 4 | const loader = {loaders: [serverDomWebpack, ...base.loaders]} 5 | 6 | export default loader 7 | -------------------------------------------------------------------------------- /website/loader.js: -------------------------------------------------------------------------------- 1 | import {createLoader} from '@mdx-js/node-loader' 2 | import * as babel from '@node-loader/babel' 3 | import config from './mdx-config.js' 4 | 5 | const loader = {loaders: [createLoader(config), babel]} 6 | 7 | export default loader 8 | -------------------------------------------------------------------------------- /packages/mdx/lib/util/extnames.js: -------------------------------------------------------------------------------- 1 | // @ts-expect-error: untyped. 2 | import markdownExtensions from 'markdown-extensions' 3 | 4 | export const mdx = ['.mdx'] 5 | /** @type {Array} */ 6 | export const md = markdownExtensions.map((/** @type {string} */ d) => '.' + d) 7 | -------------------------------------------------------------------------------- /packages/node-loader/test/react-18-node-loader.js: -------------------------------------------------------------------------------- 1 | import {createLoader} from '../index.js' 2 | 3 | // Load is for Node 17+, the rest for 12, 14, 16. 4 | const {load, getFormat, transformSource} = createLoader({ 5 | fixRuntimeWithoutExportMap: false 6 | }) 7 | 8 | export {load, getFormat, transformSource} 9 | -------------------------------------------------------------------------------- /packages/node-loader/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @typedef {import('./lib/index.js').CompileOptions} Options 3 | */ 4 | 5 | import {createLoader} from './lib/index.js' 6 | 7 | const {load, getFormat, transformSource} = createLoader() 8 | 9 | export {load, getFormat, transformSource} 10 | export {createLoader} from './lib/index.js' 11 | -------------------------------------------------------------------------------- /packages/mdx/lib/node-types.js: -------------------------------------------------------------------------------- 1 | /** 2 | * List of node types made by `mdast-util-mdx`, which have to be passed 3 | * through untouched from the mdast tree to the hast tree. 4 | */ 5 | export const nodeTypes = [ 6 | 'mdxFlowExpression', 7 | 'mdxJsxFlowElement', 8 | 'mdxJsxTextElement', 9 | 'mdxTextExpression', 10 | 'mdxjsEsm' 11 | ] 12 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2020", 4 | "lib": ["ES2020"], 5 | "module": "ES2020", 6 | "moduleResolution": "node", 7 | "allowJs": true, 8 | "checkJs": true, 9 | "declaration": true, 10 | "emitDeclarationOnly": true, 11 | "allowSyntheticDefaultImports": true, 12 | "skipLibCheck": true, 13 | "strict": true 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /docs/_component/note.server.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | const known = new Set(['info', 'legacy', 'important']) 4 | 5 | export function Note(props) { 6 | const {children, type} = props 7 | const className = ['note'] 8 | 9 | if (known.has(type)) className.push(type) 10 | else { 11 | throw new Error('Unknown note type `' + type + '`') 12 | } 13 | 14 | return
{children}
15 | } 16 | -------------------------------------------------------------------------------- /packages/loader/index.cjs: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | /** 4 | * Webpack loader 5 | * 6 | * @todo once webpack supports ESM loaders, remove this wrapper. 7 | * 8 | * @param {string} code 9 | */ 10 | module.exports = function (code) { 11 | const callback = this.async() 12 | // Note that `import()` caches, so this should be fast enough. 13 | import('./lib/index.js').then((module) => 14 | module.loader.call(this, code, callback) 15 | ) 16 | } 17 | -------------------------------------------------------------------------------- /website/schema-description.js: -------------------------------------------------------------------------------- 1 | export const schema = { 2 | strip: ['script', 'style'], 3 | ancestors: {}, 4 | protocols: {href: ['http', 'https']}, 5 | tagNames: [ 6 | 'ul', 7 | 'ol', 8 | 'li', 9 | 'pre', 10 | 'code', 11 | 'strong', 12 | 'p', 13 | 'b', 14 | 'em', 15 | 'i', 16 | 'strike', 17 | 's', 18 | 'del', 19 | 'a' 20 | ], 21 | attributes: { 22 | a: ['href'], 23 | '*': [] 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/esbuild/test/files/components.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | /** 4 | * @param {Record} props 5 | */ 6 | export function Pill(props) { 7 | return React.createElement('span', {...props, style: {color: 'red'}}) 8 | } 9 | 10 | /** 11 | * @param {Record} props 12 | */ 13 | export function Layout(props) { 14 | return React.createElement('div', {...props, style: {color: 'red'}}) 15 | } 16 | 17 | export default Layout 18 | -------------------------------------------------------------------------------- /packages/mdx/test/context/components.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | /** 4 | * @param {Record} props 5 | */ 6 | export function Pill(props) { 7 | return React.createElement('span', {...props, style: {color: 'red'}}) 8 | } 9 | 10 | /** 11 | * @param {Record} props 12 | */ 13 | export function Layout(props) { 14 | return React.createElement('div', {...props, style: {color: 'red'}}) 15 | } 16 | 17 | export default Layout 18 | -------------------------------------------------------------------------------- /packages/mdx/lib/util/extnames-to-regex.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Utility to turn a list of extnames (*with* dots) into an expression. 3 | * 4 | * @param {Array} extnames 5 | * List of extnames. 6 | * @returns {RegExp} 7 | * Regex matching them. 8 | */ 9 | export function extnamesToRegex(extnames) { 10 | // eslint-disable-next-line security/detect-non-literal-regexp 11 | return new RegExp( 12 | '\\.(' + extnames.map((d) => d.slice(1)).join('|') + ')([?#]|$)' 13 | ) 14 | } 15 | -------------------------------------------------------------------------------- /packages/mdx/lib/plugin/rehype-recma.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @typedef {import('estree-jsx').Program} Program 3 | * @typedef {import('hast').Root} Root 4 | */ 5 | 6 | import {toEstree} from 'hast-util-to-estree' 7 | 8 | /** 9 | * A plugin to transform an HTML (hast) tree to a JS (estree). 10 | * `hast-util-to-estree` does all the work for us! 11 | * 12 | * @type {import('unified').Plugin, Root, Program>} 13 | */ 14 | export function rehypeRecma() { 15 | return (tree) => toEstree(tree) 16 | } 17 | -------------------------------------------------------------------------------- /packages/mdx/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @typedef {import('./lib/core.js').ProcessorOptions} ProcessorOptions 3 | * @typedef {import('./lib/compile.js').CompileOptions} CompileOptions 4 | * @typedef {import('./lib/evaluate.js').EvaluateOptions} EvaluateOptions 5 | */ 6 | 7 | export {createProcessor} from './lib/core.js' 8 | export {compile, compileSync} from './lib/compile.js' 9 | export {evaluate, evaluateSync} from './lib/evaluate.js' 10 | export {run, runSync} from './lib/run.js' 11 | export {nodeTypes} from './lib/node-types.js' 12 | -------------------------------------------------------------------------------- /packages/mdx/lib/util/estree-util-is-declaration.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @typedef {import('estree-jsx').Declaration} Declaration 3 | */ 4 | 5 | /** 6 | * @param {unknown} node 7 | * @returns {node is Declaration} 8 | */ 9 | export function isDeclaration(node) { 10 | /** @type {string} */ 11 | // @ts-expect-error Hush typescript, looks like `type` is available. 12 | const type = node && typeof node === 'object' && node.type 13 | return Boolean( 14 | type === 'FunctionDeclaration' || 15 | type === 'ClassDeclaration' || 16 | type === 'VariableDeclaration' 17 | ) 18 | } 19 | -------------------------------------------------------------------------------- /packages/loader/index.d.ts: -------------------------------------------------------------------------------- 1 | import type {ProcessorOptions} from '@mdx-js/mdx/lib/core.js' 2 | import type {LoaderContext} from 'webpack' 3 | 4 | /** 5 | * A Webpack loader to compile MDX to JavaScript. 6 | * 7 | * [Reference for Loader API](https://webpack.js.org/api/loaders/) 8 | * 9 | * @this {LoaderContext} 10 | * @param {string} value 11 | * The original module source code. 12 | * @returns {void} 13 | */ 14 | declare function mdxLoader(this: LoaderContext, value: string): void 15 | 16 | export default mdxLoader 17 | 18 | export type Options = ProcessorOptions 19 | -------------------------------------------------------------------------------- /docs/_component/snowfall.server.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | const data = [6, 5, 2, 4.5, 1.5, 2.5, 2, 2.5, 1.5, 2.5, 3.5, 7] 4 | 5 | export function Chart(props) { 6 | return ( 7 |
8 | {data.map((d, i) => ( 9 |
18 | ))} 19 |
20 | ) 21 | } 22 | -------------------------------------------------------------------------------- /renovate.json5: -------------------------------------------------------------------------------- 1 | { 2 | extends: ['config:base', ':preserveSemverRanges'], 3 | schedule: 'before 3am on Monday', 4 | packageRules: [ 5 | { 6 | matchPackageNames: [ 7 | // `react`/`react-dom`/`react-server-dom-webpack` latest don’t support 8 | // RSC. 9 | 'react', 10 | 'react-dom', 11 | 'react-fetch', 12 | 'react-server-dom-webpack', 13 | // `node-loader@2` depends on Node 16+. Our website is on Vercel/AWS which don’t support Node 16. 14 | '@node-loader/babel', 15 | '@node-loader/core' 16 | ], 17 | enabled: false 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /docs/404.server.mdx: -------------------------------------------------------------------------------- 1 | import {Note} from './_component/note.server.js' 2 | export {Home as default} from './_component/home.server.js' 3 | export const navExclude = true 4 | 5 | # 404: Not found 6 | 7 | Aww, snap. 8 | Unfortunately this page doesn’t exist. 9 | Perhaps you can find what you’re looking for [on GitHub][search]? 10 | 11 | 12 | **Note**: Did you come here from a website linking to it? 13 | Pretty sure this page used to exist? 14 | Please [open an issue](https://github.com/mdx-js/mdx/issues/new) to let us 15 | know so we can fix it! 16 | 17 | 18 | [search]: https://github.com/mdx-js/mdx/search 19 | -------------------------------------------------------------------------------- /docs/_asset/index.client.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import {hydrateRoot} from 'react-dom/client' 3 | import {createFromFetch} from 'react-server-dom-webpack' 4 | import {Root} from './root.client.js' 5 | 6 | window.addEventListener('DOMContentLoaded', main) 7 | 8 | if ('paintWorklet' in CSS) { 9 | CSS.paintWorklet.addModule( 10 | 'https://www.unpkg.com/css-houdini-squircle@0.2.1/squircle.min.js' 11 | ) 12 | } 13 | 14 | async function main() { 15 | const nljson = document.querySelector('#payload').dataset.src 16 | const $root = document.querySelector('#root') 17 | hydrateRoot($root, ) 18 | } 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | coverage/ 3 | node_modules/ 4 | /packages/esbuild/**/*.d.ts 5 | /packages/loader/lib/**/*.d.ts 6 | /packages/loader/test/**/*.d.ts 7 | /packages/mdx/**/*.d.ts 8 | /packages/node-loader/**/*.d.ts 9 | /packages/preact/lib/**/*.d.ts 10 | /packages/preact/test/**/*.d.ts 11 | /packages/preact/index.d.ts 12 | /packages/react/lib/**/*.d.ts 13 | /packages/react/test/**/*.d.ts 14 | /packages/react/index.d.ts 15 | /packages/register/**/*.d.ts 16 | /packages/remark-mdx/test/**/*.d.ts 17 | /packages/remark-mdx/*.d.ts 18 | /packages/rollup/**/*.d.ts 19 | /packages/vue/lib/**/*.d.ts 20 | /packages/vue/test/**/*.d.ts 21 | /packages/vue/index.d.ts 22 | /public/ 23 | -------------------------------------------------------------------------------- /packages/mdx/lib/plugin/rehype-remove-raw.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @typedef {import('hast').Root} Root 3 | */ 4 | 5 | import {visit} from 'unist-util-visit' 6 | 7 | /** 8 | * A tiny plugin that removes raw HTML. 9 | * This is needed if the format is `md` and `rehype-raw` was not used to parse 10 | * dangerous HTML into nodes. 11 | * 12 | * @type {import('unified').Plugin, Root>} 13 | */ 14 | export function rehypeRemoveRaw() { 15 | return (tree) => { 16 | visit(tree, 'raw', (_, index, parent) => { 17 | if (parent && typeof index === 'number') { 18 | parent.children.splice(index, 1) 19 | return index 20 | } 21 | }) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /docs/guides/index.server.mdx: -------------------------------------------------------------------------------- 1 | import {NavGroup} from '../_component/nav.server.js' 2 | export const navSortSelf = 2 3 | export const info = { 4 | author: [{name: 'MDX Contributors'}], 5 | published: new Date('2021-11-01'), 6 | modified: new Date('2021-11-01') 7 | } 8 | 9 | # Guides 10 | 11 | These guides explain how to accomplish several common use cases and patterns 12 | around MDX. 13 | 14 | { 15 | (() => { 16 | const category = props.navTree.children.find( 17 | item => item.name === '/guides/' 18 | ) 19 | 20 | return ( 21 | 24 | ) 25 | })() 26 | } 27 | -------------------------------------------------------------------------------- /packages/mdx/lib/util/estree-util-to-binary-addition.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @typedef {import('estree-jsx').Expression} Expression 3 | */ 4 | 5 | /** 6 | * @param {Array} expressions 7 | */ 8 | export function toBinaryAddition(expressions) { 9 | let index = -1 10 | /** @type {Expression|undefined} */ 11 | let left 12 | 13 | while (++index < expressions.length) { 14 | const right = expressions[index] 15 | left = left ? {type: 'BinaryExpression', left, operator: '+', right} : right 16 | } 17 | 18 | // Just for types. 19 | /* c8 ignore next */ 20 | if (!left) throw new Error('Expected non-empty `expressions` to be passed') 21 | 22 | return left 23 | } 24 | -------------------------------------------------------------------------------- /docs/_asset/root.client.js: -------------------------------------------------------------------------------- 1 | /* eslint-env browser */ 2 | 3 | import React, {Suspense} from 'react' 4 | 5 | export function Root(props) { 6 | const {response} = props 7 | 8 | return ( 9 | 10 | 11 | 12 | ) 13 | 14 | function Content() { 15 | return response.readRoot() 16 | } 17 | } 18 | 19 | if (typeof document !== 'undefined') { 20 | const current = document.querySelectorAll('[aria-current]') 21 | let index = -1 22 | while (++index < current.length) { 23 | const node = current[index] 24 | if (typeof node.scrollIntoViewIfNeeded === 'function') { 25 | node.scrollIntoViewIfNeeded() 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /docs/_static/icon.svg: -------------------------------------------------------------------------------- 1 | 2 | MDX 3 | 11 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /docs/community/index.server.mdx: -------------------------------------------------------------------------------- 1 | import {NavGroup} from '../_component/nav.server.js' 2 | export const navSortSelf = 6 3 | export const info = { 4 | author: [{name: 'MDX Contributors'}], 5 | published: new Date('2021-11-01'), 6 | modified: new Date('2021-11-01') 7 | } 8 | 9 | # Community 10 | 11 | These pages explain how to contribute, get help, sponsor us, share your work, 12 | and some background information. 13 | 14 | { 15 | (() => { 16 | const category = props.navTree.children.find( 17 | item => item.name === '/community/' 18 | ) 19 | 20 | return ( 21 | 24 | ) 25 | })() 26 | } 27 | -------------------------------------------------------------------------------- /docs/blog/index.server.mdx: -------------------------------------------------------------------------------- 1 | import {BlogGroup} from '../_component/blog.server.js' 2 | export const navExcludeGroup = true 3 | export const navSortSelf = 7 4 | export const navSortItems = 'navSortSelf,meta.published:desc' 5 | export const info = { 6 | author: [{name: 'MDX Contributors'}], 7 | published: new Date('2021-11-01'), 8 | modified: new Date('2021-11-01') 9 | } 10 | 11 | # Blog 12 | 13 | The latest news about MDX. 14 | 15 | { 16 | (() => { 17 | const category = props.navTree.children.find( 18 | item => item.name === '/blog/' 19 | ) 20 | 21 | return ( 22 | 25 | ) 26 | })() 27 | } 28 | -------------------------------------------------------------------------------- /packages/mdx/lib/util/estree-util-create.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @typedef {import('estree-jsx').Node} Node 3 | */ 4 | 5 | /** 6 | * @template {Node} N 7 | * @param {Node} template 8 | * @param {N} node 9 | * @returns {N} 10 | */ 11 | export function create(template, node) { 12 | /** @type {Array} */ 13 | // @ts-expect-error: `start`, `end`, `comments` are custom Acorn fields. 14 | const fields = ['start', 'end', 'loc', 'range', 'comments'] 15 | let index = -1 16 | 17 | while (++index < fields.length) { 18 | const field = fields[index] 19 | 20 | if (field in template) { 21 | // @ts-expect-error: assume they’re settable. 22 | node[field] = template[field] 23 | } 24 | } 25 | 26 | return node 27 | } 28 | -------------------------------------------------------------------------------- /docs/_component/home.server.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import {NavSite, NavSiteSkip} from './nav-site.server.js' 3 | import {FootSite} from './foot-site.server.js' 4 | 5 | export function Home(props) { 6 | const {name, navTree, children} = props 7 | 8 | return ( 9 |
10 | 11 |
12 | {props.meta.schemaOrg && ( 13 | 16 | )} 17 |
18 |
{children}
19 |
20 | 21 |
22 | 23 |
24 | ) 25 | } 26 | -------------------------------------------------------------------------------- /docs/docs/index.server.mdx: -------------------------------------------------------------------------------- 1 | import {NavGroup} from '../_component/nav.server.js' 2 | export const navSortSelf = 1 3 | export const info = { 4 | author: [{name: 'MDX Contributors'}], 5 | published: new Date('2021-11-01'), 6 | modified: new Date('2021-11-01') 7 | } 8 | 9 | # Docs 10 | 11 | These docs explain the core concepts of MDX. 12 | How the format works, how to add it to your site, how to use MDX files, and how 13 | to extend them. 14 | Reading through these should give you a good understanding of MDX. 15 | 16 | { 17 | (() => { 18 | const category = props.navTree.children.find( 19 | item => item.name === '/docs/' 20 | ) 21 | 22 | return ( 23 | 26 | ) 27 | })() 28 | } 29 | -------------------------------------------------------------------------------- /packages/vue/lib/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @typedef {import('mdx/types').MDXComponents} Components 3 | */ 4 | 5 | import {provide, inject, createVNode, Fragment} from 'vue' 6 | 7 | /** @type {import('vue').Component<{components?: Components}>} */ 8 | export const MDXProvider = { 9 | name: 'MDXProvider', 10 | props: {components: {type: Object, default: () => ({})}}, 11 | setup(props) { 12 | provide('$mdxComponents', props.components) 13 | }, 14 | /** 15 | * @this {import('vue').ComponentPublicInstance} 16 | */ 17 | render() { 18 | return createVNode( 19 | Fragment, 20 | null, 21 | this.$slots.default ? this.$slots.default() : [] 22 | ) 23 | } 24 | } 25 | 26 | /** @returns {Components} */ 27 | export function useMDXComponents() { 28 | return inject('$mdxComponents', {}) 29 | } 30 | -------------------------------------------------------------------------------- /packages/mdx/lib/run.js: -------------------------------------------------------------------------------- 1 | /** @type {new (code: string, ...args: Array) => Function} **/ 2 | const AsyncFunction = Object.getPrototypeOf(run).constructor 3 | 4 | /** 5 | * Asynchronously run code. 6 | * 7 | * @param {{toString(): string}} file 8 | * JS document to run. 9 | * @param {unknown} options 10 | * @return {Promise<*>} 11 | */ 12 | export async function run(file, options) { 13 | // V8 on Erbium. 14 | /* c8 ignore next 2 */ 15 | return new AsyncFunction(String(file))(options) 16 | } 17 | 18 | /** 19 | * Synchronously run code. 20 | * 21 | * @param {{toString(): string}} file 22 | * JS document to run. 23 | * @param {unknown} options 24 | * @return {*} 25 | */ 26 | export function runSync(file, options) { 27 | // eslint-disable-next-line no-new-func 28 | return new Function(String(file))(options) 29 | } 30 | -------------------------------------------------------------------------------- /docs/packages/index.server.mdx: -------------------------------------------------------------------------------- 1 | import {NavGroup} from '../_component/nav.server.js' 2 | export const navSortSelf = 3 3 | export const info = { 4 | author: [{name: 'MDX Contributors'}], 5 | published: new Date('2021-11-01'), 6 | modified: new Date('2021-11-01') 7 | } 8 | 9 | # Packages 10 | 11 | This index lists the packages that are maintained in our monorepo. 12 | They include `@mdx-js/mdx`, which is our core compiler; `remark-mdx`, which is 13 | the remark plugin to support the MDX syntax; and several integrations with 14 | bundlers and frontend frameworks. 15 | 16 | { 17 | (() => { 18 | const category = props.navTree.children.find( 19 | item => item.name === '/packages/' 20 | ) 21 | 22 | return ( 23 | 26 | ) 27 | })() 28 | } 29 | -------------------------------------------------------------------------------- /docs/_component/icon/twitter.server.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | export function Twitter() { 4 | return ( 5 | 13 | Twitter 14 | 18 | 19 | ) 20 | } 21 | -------------------------------------------------------------------------------- /docs/_component/icon/mdx.server.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | export function Mdx() { 4 | return ( 5 | 13 | MDX 14 | 15 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | ) 32 | } 33 | -------------------------------------------------------------------------------- /docs/_component/icon/open-collective.server.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | export function OpenCollective() { 4 | return ( 5 | 13 | OpenCollective 14 | 18 | 22 | 23 | ) 24 | } 25 | -------------------------------------------------------------------------------- /packages/register/test/index.test.cjs: -------------------------------------------------------------------------------- 1 | /** 2 | * @typedef {import('mdx/types').MDXContent} MDXContent 3 | */ 4 | 5 | 'use strict' 6 | 7 | const path = require('path') 8 | const fs = require('fs').promises 9 | const {test} = require('uvu') 10 | const assert = require('uvu/assert') 11 | const React = require('react') 12 | const {renderToStaticMarkup} = require('react-dom/server') 13 | 14 | test('@mdx-js/register', async () => { 15 | const base = path.resolve(path.join('test')) 16 | 17 | await fs.writeFile( 18 | path.join(base, 'register.mdx'), 19 | 'export const Message = () => <>World!\n\n# Hello, ' 20 | ) 21 | 22 | // OMG, it works! 23 | const Content = /** @type {MDXContent} */ ( 24 | require('./register.mdx') // type-coverage:ignore-line 25 | ) 26 | 27 | assert.equal( 28 | renderToStaticMarkup(React.createElement(Content)), 29 | '

Hello, World!

', 30 | 'should compile' 31 | ) 32 | 33 | await fs.unlink(path.join(base, 'register.mdx')) 34 | }) 35 | 36 | test.run() 37 | -------------------------------------------------------------------------------- /docs/playground.server.mdx: -------------------------------------------------------------------------------- 1 | import {Note} from './_component/note.server.js' 2 | import {Editor} from './_component/editor.client.js' 3 | export const navSortSelf = 5 4 | export const info = { 5 | author: [ 6 | {name: 'John Otander', github: 'johno', twitter: '4lpine'}, 7 | {name: 'Titus Wormer', github: 'wooorm', twitter: 'wooorm'} 8 | ], 9 | published: new Date('2021-09-13'), 10 | modified: new Date('2021-11-01') 11 | } 12 | export const playgroundSource = `Hello, world! 13 | Below is an example of markdown in JSX. 14 | 15 |
16 | Try and change the background color to \`tomato\`. 17 |
` 18 | 19 | # Playground 20 | 21 | Here you can play with the MDX format. 22 | Write some MDX to find out what it turns into. {/* more */} 23 | You can see the rendered result, the generated code, and the intermediary 24 | ASTs. 25 | This can be helpful for debugging or exploring. 26 | To read about how the MDX format works, we recommend that you start with 27 | [§ What is MDX][what]. 28 | 29 | 30 | 31 | [what]: /docs/what-is-mdx/ 32 | -------------------------------------------------------------------------------- /packages/mdx/lib/util/estree-util-declaration-to-expression.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @typedef {import('estree-jsx').Declaration} Declaration 3 | * @typedef {import('estree-jsx').Expression} Expression 4 | */ 5 | 6 | /** 7 | * Turn a declaration into an expression. 8 | * Doesn’t work for variable declarations, but that’s fine for our use case 9 | * because currently we’re using this utility for export default declarations, 10 | * which can’t contain variable declarations. 11 | * 12 | * @param {Declaration} declaration 13 | * @returns {Expression} 14 | */ 15 | export function declarationToExpression(declaration) { 16 | if (declaration.type === 'FunctionDeclaration') { 17 | return {...declaration, type: 'FunctionExpression'} 18 | } 19 | 20 | if (declaration.type === 'ClassDeclaration') { 21 | return {...declaration, type: 'ClassExpression'} 22 | /* Internal utility so the next shouldn’t happen or a maintainer is making a 23 | * mistake. */ 24 | /* c8 ignore next 4 */ 25 | } 26 | 27 | // Probably `VariableDeclaration`. 28 | throw new Error('Cannot turn `' + declaration.type + '` into an expression') 29 | } 30 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Compositor and Vercel, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/rollup/license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2021 Titus Wormer 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/esbuild/license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2021 Titus Wormer 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/node-loader/license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2021 Titus Wormer 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/register/license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2021 Titus Wormer 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/loader/license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Compositor and Vercel, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/preact/license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Compositor and Vercel, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/react/license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Compositor and Vercel, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/mdx/license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Compositor, Inc. and Vercel, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/vue/license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Compositor, Inc. and Vercel, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/remark-mdx/license: -------------------------------------------------------------------------------- 1 | (The MIT License) 2 | 3 | Copyright (c) 2020 Titus Wormer 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | 'Software'), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: main 2 | on: 3 | - pull_request 4 | - push 5 | jobs: 6 | small: 7 | name: test / ${{matrix.os}} / ${{matrix.node}} 8 | runs-on: ${{matrix.os}} 9 | env: 10 | PUPPETEER_SKIP_DOWNLOAD: 1 11 | steps: 12 | - uses: actions/checkout@v3 13 | with: 14 | fetch-depth: 0 15 | - uses: actions/setup-node@v3 16 | with: 17 | node-version: ${{matrix.node}} 18 | cache: npm 19 | - run: npm install -g npm && npm install 20 | - run: npm run test-api 21 | strategy: 22 | matrix: 23 | os: 24 | - macos-latest 25 | - windows-latest 26 | node: 27 | - '*' 28 | include: 29 | - os: ubuntu-latest 30 | node: lts/fermium 31 | full: 32 | name: full build 33 | runs-on: ubuntu-latest 34 | env: 35 | PUPPETEER_SKIP_DOWNLOAD: 1 36 | steps: 37 | - uses: actions/checkout@v3 38 | with: 39 | fetch-depth: 0 40 | - uses: actions/setup-node@v3 41 | with: 42 | node-version: '*' 43 | cache: npm 44 | - run: npm install -g npm && npm install 45 | - run: npm test 46 | - uses: codecov/codecov-action@v2 47 | -------------------------------------------------------------------------------- /docs/_component/icon/github.server.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | export function GitHub() { 4 | return ( 5 | 13 | GitHub 14 | 20 | 21 | ) 22 | } 23 | -------------------------------------------------------------------------------- /packages/mdx/lib/plugin/recma-stringify.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @typedef {import('estree-jsx').Program} Program 3 | * @typedef {typeof import('source-map').SourceMapGenerator} SourceMapGenerator 4 | * 5 | * @typedef RecmaStringifyOptions 6 | * @property {SourceMapGenerator} [SourceMapGenerator] 7 | * Generate a source map by passing a `SourceMapGenerator` from `source-map` 8 | * in. 9 | */ 10 | 11 | import {toJs, jsx} from 'estree-util-to-js' 12 | 13 | /** 14 | * A plugin that adds an esast compiler: a small wrapper around `astring` to add 15 | * support for serializing JSX. 16 | * 17 | * @type {import('unified').Plugin<[RecmaStringifyOptions]|[], Program, string>} 18 | */ 19 | export function recmaStringify(options = {}) { 20 | const {SourceMapGenerator} = options 21 | 22 | Object.assign(this, {Compiler: compiler}) 23 | 24 | /** @type {import('unified').CompilerFunction} */ 25 | function compiler(tree, file) { 26 | const result = SourceMapGenerator 27 | ? toJs(tree, { 28 | filePath: file.path || 'unknown.mdx', 29 | SourceMapGenerator, 30 | handlers: jsx 31 | }) 32 | : toJs(tree, {handlers: jsx}) 33 | 34 | file.map = result.map 35 | 36 | return result.value 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /docs/_component/sort.js: -------------------------------------------------------------------------------- 1 | import dlv from 'dlv' 2 | 3 | const collator = new Intl.Collator('en').compare 4 | 5 | export function sortItems(items, sortString = 'navSortSelf,meta.title') { 6 | const fields = sortString.split(',').map((d) => { 7 | const [field, order = 'asc'] = d.split(':') 8 | 9 | if (order !== 'asc' && order !== 'desc') { 10 | throw new Error('Cannot order as `' + order + '`') 11 | } 12 | 13 | return [field, order] 14 | }) 15 | 16 | return [...items].sort((left, right) => { 17 | let index = -1 18 | 19 | while (++index < fields.length) { 20 | const [field, order] = fields[index] 21 | let a = dlv(left.data, field) 22 | let b = dlv(right.data, field) 23 | 24 | if (a && typeof a === 'object' && 'valueOf' in a) a = a.valueOf() 25 | if (b && typeof b === 'object' && 'valueOf' in b) b = b.valueOf() 26 | 27 | const score = 28 | typeof a === 'number' || typeof b === 'number' 29 | ? a === null || a === undefined 30 | ? 1 31 | : b === null || b === undefined 32 | ? -1 33 | : a - b 34 | : collator(a, b) 35 | const result = order === 'asc' ? score : -score 36 | if (result) return result 37 | } 38 | 39 | return 0 40 | }) 41 | } 42 | -------------------------------------------------------------------------------- /packages/node-loader/test/index.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @typedef {import('mdx/types').MDXContent} MDXContent 3 | */ 4 | 5 | import {promises as fs} from 'fs' 6 | import {test} from 'uvu' 7 | import * as assert from 'uvu/assert' 8 | import React from 'react' 9 | import {renderToStaticMarkup} from 'react-dom/server' 10 | 11 | test('@mdx-js/node-loader', async () => { 12 | await fs.writeFile( 13 | new URL('esm-loader.mdx', import.meta.url), 14 | 'export const Message = () => <>World!\n\n# Hello, ' 15 | ) 16 | 17 | /** @type {MDXContent} */ 18 | let Content 19 | 20 | try { 21 | Content = (await import('./esm-loader.mdx')).default // type-coverage:ignore-line 22 | } catch (error) { 23 | const exception = /** @type {NodeJS.ErrnoException} */ (error) 24 | if (exception.code === 'ERR_UNKNOWN_FILE_EXTENSION') { 25 | await fs.unlink(new URL('esm-loader.mdx', import.meta.url)) 26 | throw new Error( 27 | 'Please run Node with `--experimental-loader=./esm-loader.js` to test the ESM loader' 28 | ) 29 | } 30 | 31 | throw error 32 | } 33 | 34 | assert.equal( 35 | renderToStaticMarkup(React.createElement(Content)), 36 | '

Hello, World!

', 37 | 'should compile' 38 | ) 39 | 40 | await fs.unlink(new URL('esm-loader.mdx', import.meta.url)) 41 | }) 42 | 43 | test.run() 44 | -------------------------------------------------------------------------------- /packages/remark-mdx/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @typedef {import('mdast').Root} Root 3 | * @typedef {import('micromark-extension-mdxjs').Options} MicromarkOptions 4 | * @typedef {import('mdast-util-mdx').ToMarkdownOptions} ToMarkdownOptions 5 | * @typedef {MicromarkOptions & ToMarkdownOptions} Options 6 | * 7 | * @typedef {import('mdast-util-mdx')} DoNotTouchAsThisImportItIncludesMdxInTree 8 | */ 9 | 10 | import {mdxjs} from 'micromark-extension-mdxjs' 11 | import {mdxFromMarkdown, mdxToMarkdown} from 'mdast-util-mdx' 12 | 13 | /** 14 | * Plugin to support MDX (import/exports: `export {x} from 'y'`; expressions: 15 | * `{1 + 1}`; and JSX: `