Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] MDX V2 #1077

Closed
wants to merge 113 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
9d30680
Rewrite how MDX is parsed (#1039)
wooorm May 20, 2020
caac874
Rename remark-mdxjs-* to remark-mdx-*
johno May 20, 2020
08c809a
v2.0.0-next.0
johno May 20, 2020
4bf052c
types: add typescript typings for @mdx-js/mdx, @mdx-js/react, @mdx-js…
ChristianMurphy May 20, 2020
dc1c541
Fix package deps in root
johno May 20, 2020
4c59ce6
ci: add node 14 to test matrix (#1080)
ChristianMurphy May 20, 2020
65af47c
Break three main tests into their own scripts
johno May 20, 2020
e2eb4ee
types: add typescript typings for remark-mdx, remark-mdx-remove-expor…
ChristianMurphy May 21, 2020
a3d8f08
types: add types to test utils (#1083)
ChristianMurphy May 21, 2020
569f82f
Make preid next to match dist tag
johno May 21, 2020
166fd9d
v2.0.0-next.1
johno May 21, 2020
ea9970a
Bump deps, fix core-js version in babel configs
johno Jul 16, 2020
db93304
Improve export name extraction for shortcode generation (#1160)
johno Jul 17, 2020
577d48f
Fix some linting
johno Jul 17, 2020
3ca8e0a
Fix linting (#1161)
johno Jul 17, 2020
afd60c2
Break out linting into its own action
johno Jul 17, 2020
7829b88
Move publish to its own action
johno Jul 17, 2020
fa091d2
v2.0.0-next.2
johno Jul 17, 2020
d0059c8
v2.0.0-next.3
johno Jul 17, 2020
d08c5b6
Make testing matrix simpler (#1173)
johno Jul 22, 2020
649dbd8
Implement inline link serialization that doesn't wrap them in angle (…
johno Jul 22, 2020
e1b45e3
v2.0.0-next.4
johno Jul 22, 2020
0da2fcf
Specify pre-dist-tag
johno Jul 22, 2020
6098d94
Remove deprecated plugin options, fixes #718 (#1174)
johno Jul 22, 2020
cc95646
ci(github): update github actions and dtslint to latest (#1178)
ChristianMurphy Jul 23, 2020
42077e4
ci(github): update github actions to latest versions (#1180)
ChristianMurphy Jul 23, 2020
9ac9755
docs(typescript): document how to use mdx 2 with typescript (#1181)
ChristianMurphy Jul 23, 2020
f59b174
Make type test run in their own action, closes #1172 (#1179)
johno Jul 23, 2020
5c15a00
fix(remark-mdx): move remark-stringify to deps (#1190)
redallen Jul 27, 2020
bf7deab
v2.0.0-next.5
johno Jul 27, 2020
8b36b9f
next.5
johno Jul 27, 2020
cbfeb8b
v2.0.0-next.6
johno Jul 27, 2020
9a33ae5
Implement ability to opt out of MDXProvider components (#1175)
johno Jul 30, 2020
b6f3fdf
v2.0.0-next.7
johno Jul 30, 2020
b8bedc9
Remove layout props in compiled jsx (#1199)
johno Jul 31, 2020
d76085f
fix(mdx): add additional typings to mdx api (#1211)
lonyele Aug 3, 2020
8b4723f
modernize 2.0 preact build (#1269)
ChristopherBiscardi Sep 18, 2020
df2487a
Update yarn.lock
johno Sep 18, 2020
e194fc1
v2.0.0-next.8
johno Sep 18, 2020
e7e9d46
Fix Vue, document and test rest
wooorm Nov 19, 2020
9f5a91d
Fix tests on next
wooorm Nov 24, 2020
5d08233
Refactor and test `remark-mdxjs`
wooorm Nov 24, 2020
62931c2
Refactor `@mdx-js/mdx` to clean code, test 100%
wooorm Nov 28, 2020
8c922e4
Add types to `@mdx-js/preact` (#1233)
ChristianMurphy Dec 1, 2020
3080444
Update to remark@13 (micromark)
wooorm Dec 15, 2020
a042a9d
Update `mdast-util-to-hast`
wooorm Dec 17, 2020
421660c
Add a new homepage, because Black Lives Matter (#1094)
johno Jun 1, 2020
44038f4
Fix Tony's name
johno Jun 5, 2020
d19bea4
Update @next/mdx repo link (#1106)
rafaelalmeidatk Jun 10, 2020
28059e4
Fix casing of TypeScript (#1110)
karlhorky Jun 12, 2020
145af31
fix: add useEffect to Web Components example (#1109)
Jun 12, 2020
d3065ff
Fix npm command to start zero example (#1107)
ilhamwahabi Jun 12, 2020
dbd61b1
docs: add a space after punctuation (#1113)
Norviah Jun 19, 2020
c940327
Use blm banner
johno Jun 19, 2020
34db511
Fixed broken links (#1118)
ykadosh Jun 24, 2020
9e614be
Fixed links and improved example (#1119)
mariusGundersen Jun 29, 2020
7e2bf24
ci: Github CI Fixes (#1134)
palfrey Jul 10, 2020
735fcbf
docs: `yarn bootstrap` should be removed in favor of yarn workspaces …
JounQin Jul 11, 2020
aa6213b
Adding favicon based on MDX logo to docs (#1141)
gdgkirkley Jul 12, 2020
3b2aee7
Introduce syntax highlighting (#1140)
samrobbins85 Jul 13, 2020
40e74d6
Typescript support (#1128)
deadcoder0904 Jul 15, 2020
dd0651f
fix: quote component name in error message (#1136)
kaisugi Jul 15, 2020
d1fe44c
docs: add spaces after sentences in index (#1127)
AndersDJohnson Jul 16, 2020
837ff86
Pass filename to Babel transform for better errors (#1126)
silvenon Jul 16, 2020
92ee312
Default file to an object (#1154)
johno Jul 16, 2020
ba6cdfd
Ensure all falsy values for file are addressed (#1155)
johno Jul 17, 2020
e12799f
Fix release instructions in contributing docs (#1158)
Jul 17, 2020
041279d
Fix duplicate yarn in instructions (#1159)
Jul 17, 2020
7398b98
pin workspace deps to prevent mis-matched versions when updates are r…
peter-mouland Jul 20, 2020
84304b2
Improve runtime docs, closes #1176 (#1177)
johno Jul 22, 2020
f9895fe
Update sponsors table (#1183)
wooorm Jul 24, 2020
c9f2d25
Update social icons with react-feather (#1191)
maxcell Jul 28, 2020
19cc369
Make short codes function conditional. (#1088)
ankeetmaini Jul 29, 2020
53f8ccf
MDXConf landing page and signup form (#1200)
johno Jul 31, 2020
efc09f5
OG/Twitter preview (#1201)
johno Jul 31, 2020
5e7f0c4
Fix og image url (#1203)
johno Jul 31, 2020
3fb703d
Tweak confirmed page and conf heading for mobile
johno Jul 31, 2020
c7c05f9
Add details on how to add MDX plugins with Next.js (#1212)
samrobbins85 Aug 3, 2020
b2750d7
fix: include remark-frontmatter manually (#1204)
JounQin Aug 5, 2020
477745f
docs(getting-started/gatsby): Update gatsby link (#1224)
Biswas-N Aug 19, 2020
3f83d47
Add MDXConf banner (#1225)
johno Aug 19, 2020
680bdf9
Update conf page with speaker list and time
johno Aug 22, 2020
3d3fc01
Add Jonathan
johno Aug 22, 2020
77d10eb
Update Jonathan's talk title
johno Aug 22, 2020
c509e81
Add conf links
johno Aug 24, 2020
65e3558
Tweak theme and title
johno Aug 24, 2020
639a7b7
Add more description
johno Aug 24, 2020
c22d926
Add stream recording link
johno Aug 24, 2020
1e17e4c
Fix typo
johno Aug 24, 2020
c88072d
Add recordings
johno Aug 24, 2020
e9983a2
Improve wording
johno Aug 24, 2020
2e3a4d9
Use singular noun (#1259)
chenxsan Sep 8, 2020
52e40d6
fix code block syntax (#1260)
chenxsan Sep 8, 2020
9200202
fix edit link (#1261)
chenxsan Sep 8, 2020
d0e6b99
JetBrains plugin now available (#1252)
andrewaylett Sep 8, 2020
0210d95
Update projects.mdx (#1248)
nikobenho Sep 8, 2020
bb5ba21
fix(docs): fix link (#1235)
muescha Sep 17, 2020
6c0cb05
Health (#1226)
wooorm Sep 17, 2020
b101e71
Add info on making Next.js pick up .mdx pages (#1250)
dan-overton Sep 17, 2020
ccfde4b
Fix Lerna links (#1286)
ndresx Oct 2, 2020
6b44a02
Update math-blocks.mdx (#1278)
samrobbins85 Oct 11, 2020
61c4d55
Update sponsors
wooorm Oct 18, 2020
b1b2cde
Add annotation to use classic runtime (#1307)
ykzts Oct 20, 2020
8906385
Runtime - Added documentation for remarkPlugins (#1218)
dowi Oct 20, 2020
eca29b7
Fix broken link in `plugins.mdx`
MichaelDeBoey Oct 29, 2020
174b671
Support react 17 peer dep (#1319)
bcomnes Nov 7, 2020
d115520
Correct descriptions/tags in Table of components (#1331)
mrm007 Nov 30, 2020
0de639a
Add MDNEXT to projects page (#1309)
domitriusclark Nov 30, 2020
067cfbb
Add mdnext link
johno Nov 30, 2020
71d4185
Fix typo
chenxsan Dec 15, 2020
f0c940c
Update companies for johno and jxn (#1387)
johno Dec 16, 2020
846ee66
Remove formatting of `.mdx` files for now
wooorm Dec 17, 2020
dafdf6d
Fix tests
wooorm Dec 17, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ packages/gatsby-theme-mdx/src/components/header.js
packages/gatsby-theme-mdx/src/components/layout.js
packages/gatsby-theme-mdx/src/components/search.js

# tmp
packages/remark-mdx

# To do: Vue should be checked.
examples/vue
packages/vue

readme.md
4 changes: 1 addition & 3 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,13 @@ settings:
version: 16.3.2

overrides:
- files: '*.md'
extends: plugin:mdx/recommended

- files: '*.mdx'
extends:
- plugin:mdx/recommended
- plugin:mdx/overrides
rules:
import/no-extraneous-dependencies: 0
prettier/prettier: 0

- files:
- '**/test/**/*.js'
Expand Down
42 changes: 10 additions & 32 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,25 @@ jobs:
name: Build and Test on ${{ matrix.os }} with Node.js ${{ matrix.node }}
strategy:
matrix:
os: [macOS-latest, ubuntu-latest, windows-latest]
node: [10, 12]
os:
- ubuntu-latest
- windows-latest
node:
- 10
- 14
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1

- uses: actions/setup-node@v1
- uses: actions/checkout@v2
- uses: actions/setup-node@v2-beta
with:
node-version: ${{ matrix.node }}

- name: Setup yarn
if: matrix.os != 'windows-latest'
run: |
curl -o- -L https://yarnpkg.com/install.sh | bash
export PATH="$HOME/.yarn/bin:$PATH"

- name: Get yarn cache
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v1
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ matrix.os }}-${{ matrix.node }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ matrix.os }}-${{ matrix.node }}-yarn-

- name: Install Dependencies
- name: Install
run: yarn --frozen-lockfile
env:
CI: 'true'

- name: Build and Lint
if: matrix.os != 'windows-latest'
run: |
yarn build
yarn lint

- name: Test
run: yarn test

# To do: macos isn’t used anymore
- name: Publish CI tag to npm
if: matrix.node == 12 && matrix.os == 'macOS-latest' && github.event_name == 'push' && github.ref == 'refs/heads/master'
run: |
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CI

on: [push, pull_request]

jobs:
default:
name: Publish CI tagged release for MDX
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: actions/setup-node@v2-beta
with:
node-version: 14

- name: Setup yarn
run: |
curl -o- -L https://yarnpkg.com/install.sh | bash
export PATH="$HOME/.yarn/bin:$PATH"

- name: Install Dependencies
run: yarn --frozen-lockfile
env:
CI: 'true'

- name: Build
run: yarn build

- name: Publish CI tag to npm
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
run: |
npm set //registry.npmjs.org/:_authToken $NPM_AUTH_TOKEN
yarn publish-ci
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ artifacts
.*cache
public
.npmrc
.nyc_output/
coverage/
.yarn
14 changes: 1 addition & 13 deletions .remarkrc.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
const unified = require('unified')
const english = require('retext-english')
const wooorm = require('retext-preset-wooorm')

module.exports = {
plugins: [
'./packages/remark-mdx',
'preset-wooorm',
'preset-prettier',
[
'retext',
unified()
.use(english)
.use(wooorm)
.use({
plugins: [[require('retext-sentence-spacing'), false]]
})
],
['retext', false],
['validate-links', false]
]
}
2 changes: 1 addition & 1 deletion docs/404.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# 404

Page not found. [Return Home](/)
Page not found.[Return Home](/)
8 changes: 3 additions & 5 deletions docs/about.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# About

MDX is based on the [original `.mdx` proposal][idea] by Guillermo Rauch
([@rauchg][rauchg]). Its syntax is defined by an official [specification][].
([@rauchg][rauchg]).Its syntax is defined by an official [specification][].
The source code for MDX is available on [GitHub][] and is [MIT licensed][license].

The project is governed by the [unified collective][governance].
Expand All @@ -13,10 +13,10 @@ also available on [GitHub][design].

### Authors

- [John Otander][john] ([@4lpine][4lpine]) – [Compositor][] + [Clearbit][]
- [John Otander][john] ([@4lpine][4lpine]) – [Components AI](https://components.ai)
- [Tim Neutkens][tim] ([@timneutkens][timneutkens]) – [Vercel][]
- [Guillermo Rauch][guillermo] ([@rauchg][rauchg]) – [Vercel][]
- [Brent Jackson][brent] ([@jxnblk][jxnblk]) – [Compositor][]
- [Brent Jackson][brent] ([@jxnblk][jxnblk]) – [Gatsby](https://gatsbyjs.com)

## Related

Expand Down Expand Up @@ -70,6 +70,4 @@ These projects define the syntax which MDX blends together (MD and JSX).
[timneutkens]: https://twitter.com/timneutkens
[jxnblk]: https://twitter.com/jxnblk
[evil rabbit]: https://twitter.com/evilrabbit_
[compositor]: https://compositor.io
[vercel]: https://vercel.com
[clearbit]: https://clearbit.com
2 changes: 0 additions & 2 deletions docs/advanced/api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ const mdxText = fs.readFileSync('hello.mdx', 'utf8')
const jsx = mdx.sync(mdxText)
```

<!-- TODO: links should be updated. Can we also inline this example? -->

MDX’s [runtime][] package has [example][] usage.

## Compiler
Expand Down
14 changes: 7 additions & 7 deletions docs/advanced/components.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ documents via the [MDXProvider](#mdxprovider).
### Layout props

You’ll also notice that `layoutProps` is created based on your exports
and then passed to the wrapper. This allows for the wrapper to use
and then passed to the wrapper.This allows for the wrapper to use
those props automatically for handling things like adding an author
bio to the wrapped document.

## `makeShortcode`

There is one other function added to the compiled output: `makeShortcode`.
This is added for [shortcode support](/blog/shortcodes). It’s used in order
This is added for [shortcode support](/blog/shortcodes).It’s used in order
to stub any components that aren’t directly imported so that there won’t be
any `ReferenceError`s. If they’re passed to the `MDXProvider`, the custom
JSX pragma will pull the component from context and use that in place of the
Expand All @@ -68,9 +68,9 @@ stubbed `Button`:
const makeShortcode = name =>
function MDXDefaultShortcode(props) {
console.warn(
'Component ' +
'Component `' +
name +
' was not imported, exported, or provided by MDXProvider as global scope'
'` was not imported, exported, or provided by MDXProvider as global scope'
)
return <div {...props} />
}
Expand Down Expand Up @@ -102,9 +102,9 @@ export default () => (
### Caveats

Because MDXProvider uses React Context directly, it is affected by
the same caveats. It is therefore important that you do not declare
your components mapping inline in the JSX. Doing so will trigger a rerender
of your entire MDX page with every render cycle. Not only is this bad for
the same caveats.It is therefore important that you do not declare
your components mapping inline in the JSX.Doing so will trigger a rerender
of your entire MDX page with every render cycle.Not only is this bad for
performance, but it can cause unwanted side affects, like breaking in-page
browser navigation.

Expand Down
6 changes: 3 additions & 3 deletions docs/advanced/plugins.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ mdx.sync(mdxText, {
[rehype]: https://github.com/rehypejs/rehype
[remark-capitalize]: https://github.com/zeit/remark-capitalize
[remark-toc]: https://github.com/remarkjs/remark-toc
[remark-plugins]: https://github.com/remarkjs/remark/blob/master/doc/plugins.md#list-of-plugins
[rehype-plugins]: https://github.com/rehypejs/rehype/blob/master/doc/plugins.md#list-of-plugins
[remark-plugins]: https://github.com/remarkjs/remark/blob/main/doc/plugins.md#list-of-plugins
[rehype-plugins]: https://github.com/rehypejs/rehype/blob/main/doc/plugins.md#list-of-plugins
[retext]: https://github.com/retextjs/retext
[remarkjs/remark#224]: https://github.com/remarkjs/remark/issues/224
[visit]: https://github.com/syntax-tree/unist-util-visit
[retext-smartypants]: https://github.com/retextjs/retext-smartypants
[create-plugin]: https://unifiedjs.com/create-a-plugin.html
[create-plugin]: https://unifiedjs.com/learn/guide/create-a-plugin
5 changes: 0 additions & 5 deletions docs/advanced/runtime.mdx
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import Doc from '@mdx-js/runtime/readme.md'

<!--
TODO: add a nicer, smaller intro to the runtime: when to use it, when not to.
We can also move it to `api` maybe?
-->

# Runtime

<Doc />
2 changes: 1 addition & 1 deletion docs/advanced/transform-content.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ are many utilities you can use to work with MDX.

You can utilize [to-vfile][] to read and write MDX files
and you can leverage [remark][] and [remark-mdx][]
to parse and process MDX content. The remark-mdx library is a parsing
to parse and process MDX content.The remark-mdx library is a parsing
extension to enhance the Markdown [AST][] to understand MDX
(resulting in [MDXAST][]), giving you access and insight to MDX
attributes, namely imports, exports, and jsx.
Expand Down
81 changes: 26 additions & 55 deletions docs/advanced/typescript.mdx
Original file line number Diff line number Diff line change
@@ -1,68 +1,39 @@
# TypeScript

<!--
TODO: this feels like it’s placed weirdly.
Where could it go?
-->
MDX provides typings for many of the core packages.

Below are some basic typings to get started with:
If you want to improve upon the types, we would _love_ a PR to
improve the developer experience for TypeScript users.

```tsx
declare module '@mdx-js/react' {
import * as React from 'react'
---

type ComponentType =
| 'a'
| 'blockquote'
| 'code'
| 'delete'
| 'em'
| 'h1'
| 'h2'
| 'h3'
| 'h4'
| 'h5'
| 'h6'
| 'hr'
| 'img'
| 'inlineCode'
| 'li'
| 'ol'
| 'p'
| 'pre'
| 'strong'
| 'sup'
| 'table'
| 'td'
| 'thematicBreak'
| 'tr'
| 'ul'
## Typings for Components and Utilities

export type Components = {
[key in ComponentType]?: React.ComponentType<{children: React.ReactNode}>
}
- `@mdx-js/mdx`
- `@mdx-js/preact`
- `@mdx-js/react`
- `@mdx-js/runtime`
- `@mdx-js/vue`
- `remark-mdx`

export interface MDXProviderProps {
children: React.ReactNode
components: Components
}
export class MDXProvider extends React.Component<MDXProviderProps> {}
}
```

If you want to improve upon the types we would _love_ a PR to
improve the developer experience for TypeScript users.
Include types, no additional setup needed.

---

If you’re getting errors from TypeScript related to imports with an `*.mdx`
extension, create an `mdx.d.ts` file in your types directory and include it
inside your `tsconfig.json`.
## Typings for MDX imports

### React and Webpack

Add an `mdx.d.ts` file with the below content, and ensure it is included by the `tsconfig.json`.

```tsx
/// <reference types="@mdx-js/loader" />
```

### Vue and Webpack

Add an `mdx.d.ts` file with the below content, and ensure it is included by the `tsconfig.json`.

```tsx
// types/mdx.d.ts
declare module '*.mdx' {
let MDXComponent: (props: any) => JSX.Element
export default MDXComponent
}
/// <reference types="@mdx-js/vue-loader" />
```
Loading