Skip to content

Commit 3579aa3

Browse files
committedJun 17, 2022
Add use of tla in docs
1 parent 366ddb4 commit 3579aa3

7 files changed

+67
-123
lines changed
 

‎docs/docs/getting-started.server.mdx

+5-21
Original file line numberDiff line numberDiff line change
@@ -665,11 +665,7 @@ on how to use MDX with React Static.
665665
```js path="example.js"
666666
import {compile} from '@mdx-js/mdx'
667667

668-
main()
669-
670-
async function main() {
671-
const js = String(await compile('# hi', {jsxImportSource: '@emotion/react', /* otherOptions… */}))
672-
}
668+
const js = String(await compile('# hi', {jsxImportSource: '@emotion/react', /* otherOptions… */}))
673669
```
674670
</details>
675671

@@ -731,11 +727,7 @@ more info.
731727
```js path="example.js"
732728
import {compile} from '@mdx-js/mdx'
733729

734-
main()
735-
736-
async function main() {
737-
const js = String(await compile('# hi', {jsxImportSource: 'preact', /* otherOptions… */}))
738-
}
730+
const js = String(await compile('# hi', {jsxImportSource: 'preact', /* otherOptions… */}))
739731
```
740732
</details>
741733

@@ -811,11 +803,7 @@ info.
811803
```js path="example.js"
812804
import {compile} from '@mdx-js/mdx'
813805

814-
main()
815-
816-
async function main() {
817-
const js = String(await compile('# hi', {jsxImportSource: 'svelte-jsx', /* otherOptions… */}))
818-
}
806+
const js = String(await compile('# hi', {jsxImportSource: 'svelte-jsx', /* otherOptions… */}))
819807
```
820808
</details>
821809

@@ -835,12 +823,8 @@ which you might be using, for more info.
835823
import {compile} from '@mdx-js/mdx'
836824
import babel from '@babel/core'
837825

838-
main()
839-
840-
async function main() {
841-
const jsx = String(await compile('# hi', {jsx: true, /* otherOptions… */}))
842-
const js = (await babel.transformAsync(jsx, {plugins: ['@vue/babel-plugin-jsx']})).code
843-
}
826+
const jsx = String(await compile('# hi', {jsx: true, /* otherOptions… */}))
827+
const js = (await babel.transformAsync(jsx, {plugins: ['@vue/babel-plugin-jsx']})).code
844828
```
845829
</details>
846830

‎docs/guides/embed.server.mdx

+10-12
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const info = {
44
{name: 'Titus Wormer', github: 'wooorm', twitter: 'wooorm'}
55
],
66
published: new Date('2021-10-06'),
7-
modified: new Date('2021-11-01')
7+
modified: new Date('2022-06-17')
88
}
99

1010
# Embed
@@ -35,21 +35,19 @@ import fauxOembedTransformer from '@remark-embedder/transformer-oembed'
3535
const remarkEmbedder = fauxRemarkEmbedder.default
3636
const oembedTransformer = fauxOembedTransformer.default
3737

38-
main(`
38+
const code = `
3939
Check out this video:
4040
4141
https://www.youtube.com/watch?v=dQw4w9WgXcQ
42-
`)
43-
44-
async function main(code) {
45-
console.log(
46-
String(
47-
await compile(code, {
48-
remarkPlugins: [[remarkEmbedder, {transformers: [oembedTransformer]}]]
49-
})
50-
)
42+
`
43+
44+
console.log(
45+
String(
46+
await compile(code, {
47+
remarkPlugins: [[remarkEmbedder, {transformers: [oembedTransformer]}]]
48+
})
5149
)
52-
}
50+
)
5351
```
5452

5553
<details>

‎docs/guides/frontmatter.server.mdx

+8-16
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const info = {
44
{name: 'Titus Wormer', github: 'wooorm', twitter: 'wooorm'}
55
],
66
published: new Date('2021-10-06'),
7-
modified: new Date('2021-11-01')
7+
modified: new Date('2022-06-17')
88
}
99

1010
# Frontmatter
@@ -50,12 +50,8 @@ Then without compiling or evaluating the metadata can be accessed like so:
5050
import {promises as fs} from 'node:fs'
5151
import yaml from 'js-yaml'
5252

53-
main()
54-
55-
async function main() {
56-
console.log(yaml.loadAll(await fs.readFile('post.mdx'))[0])
57-
// Prints `{title: 'Hi, World!'}`
58-
}
53+
console.log(yaml.loadAll(await fs.readFile('post.mdx'))[0])
54+
// Prints `{title: 'Hi, World!'}`
5955
```
6056

6157
Our compiler, `@mdx-js/mdx`, doesn’t understand YAML frontmatter by default but
@@ -67,15 +63,11 @@ import {promises as fs} from 'node:fs'
6763
import remarkFrontmatter from 'remark-frontmatter'
6864
import {compile} from '@mdx-js/mdx'
6965

70-
main()
71-
72-
async function main() {
73-
console.log(
74-
await compile(await fs.readFile('post.mdx'), {
75-
remarkPlugins: [remarkFrontmatter]
76-
})
77-
)
78-
}
66+
console.log(
67+
await compile(await fs.readFile('post.mdx'), {
68+
remarkPlugins: [remarkFrontmatter]
69+
})
70+
)
7971
```
8072

8173
Now it “works”.

‎docs/guides/gfm.server.mdx

+5-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const info = {
44
{name: 'Titus Wormer', github: 'wooorm', twitter: 'wooorm'}
55
],
66
published: new Date('2021-10-06'),
7-
modified: new Date('2021-11-01')
7+
modified: new Date('2022-06-17')
88
}
99

1010
# GitHub flavored markdown (GFM)
@@ -55,15 +55,11 @@ import {promises as fs} from 'node:fs'
5555
import {compile} from '@mdx-js/mdx'
5656
import remarkGfm from 'remark-gfm'
5757

58-
main()
59-
60-
async function main() {
61-
console.log(
62-
String(
63-
await compile(await fs.readFile('example.mdx'), {remarkPlugins: [remarkGfm]})
64-
)
58+
console.log(
59+
String(
60+
await compile(await fs.readFile('example.mdx'), {remarkPlugins: [remarkGfm]})
6561
)
66-
}
62+
)
6763
```
6864

6965
<details>

‎docs/guides/math.server.mdx

+8-12
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const info = {
55
{name: 'Titus Wormer', github: 'wooorm', twitter: 'wooorm'}
66
],
77
published: new Date('2021-10-06'),
8-
modified: new Date('2022-02-01')
8+
modified: new Date('2022-06-17')
99
}
1010

1111
# Math
@@ -36,18 +36,14 @@ import {compile} from '@mdx-js/mdx'
3636
import rehypeKatex from 'rehype-katex'
3737
import remarkMath from 'remark-math'
3838

39-
main()
40-
41-
async function main() {
42-
console.log(
43-
String(
44-
await compile(await fs.readFile('example.mdx'), {
45-
remarkPlugins: [remarkMath],
46-
rehypePlugins: [rehypeKatex]
47-
})
48-
)
39+
console.log(
40+
String(
41+
await compile(await fs.readFile('example.mdx'), {
42+
remarkPlugins: [remarkMath],
43+
rehypePlugins: [rehypeKatex]
44+
})
4945
)
50-
}
46+
)
5147
```
5248

5349
<details>

‎docs/guides/syntax-highlighting.server.mdx

+6-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const info = {
55
{name: 'Titus Wormer', github: 'wooorm', twitter: 'wooorm'}
66
],
77
published: new Date('2021-10-06'),
8-
modified: new Date('2022-02-01')
8+
modified: new Date('2022-06-17')
99
}
1010

1111
# Syntax highlighting
@@ -35,15 +35,13 @@ Use either [`rehype-highlight`][rehype-highlight]
3535
import rehypeHighlight from 'rehype-highlight'
3636
import {compile} from '@mdx-js/mdx'
3737

38-
main(`~~~js
38+
const code = `~~~js
3939
console.log(1)
40-
~~~`)
40+
~~~`
4141

42-
async function main(code) {
43-
console.log(
44-
String(await compile(code, {rehypePlugins: [rehypeHighlight]}))
45-
)
46-
}
42+
console.log(
43+
String(await compile(code, {rehypePlugins: [rehypeHighlight]}))
44+
)
4745
```
4846

4947
<details>

‎packages/mdx/readme.md

+25-45
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,9 @@ Add some code in `example.js` to compile `example.mdx` to JavaScript:
7878
import {promises as fs} from 'node:fs'
7979
import {compile} from '@mdx-js/mdx'
8080

81-
main()
81+
const compiled = await compile(await fs.readFile('example.mdx'))
8282

83-
async function main() {
84-
const compiled = await compile(await fs.readFile('example.mdx'))
85-
console.log(String(compiled))
86-
}
83+
console.log(String(compiled))
8784
```
8885

8986
Yields roughly:
@@ -285,12 +282,10 @@ A module `example.js`:
285282
```js
286283
import {compile} from '@mdx-js/mdx'
287284

288-
main('export const no = 3.14\n\n# hi {no}')
285+
const code = 'export const no = 3.14\n\n# hi {no}'
289286

290-
async function main(code) {
291-
console.log(String(await compile(code, {outputFormat: 'program'}))) // Default
292-
console.log(String(await compile(code, {outputFormat: 'function-body'})))
293-
}
287+
console.log(String(await compile(code, {outputFormat: 'program'}))) // Default
288+
console.log(String(await compile(code, {outputFormat: 'function-body'})))
294289
```
295290

296291
…yields:
@@ -383,13 +378,10 @@ Say we have a module `example.js`:
383378
```js
384379
import {compile} from '@mdx-js/mdx'
385380

386-
main()
381+
const code = 'export {number} from "./data.js"\n\n# hi'
382+
const baseUrl = 'https://a.full/url' // Typically `import.meta.url`
387383

388-
async function main() {
389-
const code = 'export {number} from "./data.js"\n\n# hi'
390-
const baseUrl = 'https://a.full/url' // Typically `import.meta.url`
391-
console.log(String(await compile(code, {baseUrl})))
392-
}
384+
console.log(String(await compile(code, {baseUrl})))
393385
```
394386

395387
…now running `node example.js` yields:
@@ -428,14 +420,11 @@ import {promises as fs} from 'node:fs'
428420
import * as runtime from 'react/jsx-runtime'
429421
import {evaluate} from '@mdx-js/mdx'
430422

431-
main()
423+
const path = 'example.mdx'
424+
const value = await fs.readFile(path)
425+
const MDXContent = (await evaluate({path, value}, runtime)).default
432426

433-
async function main() {
434-
const path = 'example.mdx'
435-
const value = await fs.readFile(path)
436-
const MDXContent = (await evaluate({path, value}, runtime)).default
437-
console.log(MDXContent())
438-
}
427+
console.log(MDXContent())
439428
```
440429

441430
Running that would normally (production) yield:
@@ -451,14 +440,12 @@ Error: Expected component `NoteIcon` to be defined: you likely forgot to import,
451440
But if we change add `development: true` to our example:
452441

453442
```diff
454-
@@ -7,6 +7,6 @@ main()
455-
async function main() {
456-
const path = 'example.mdx'
457-
const value = await fs.readFile(path)
458-
- const MDXContent = (await evaluate({path, value}, runtime)).default
459-
+ const MDXContent = (await evaluate({path, value}, {development: true, ...runtime})).default
460-
console.log(MDXContent({}))
461-
}
443+
@@ -7,6 +7,6 @@
444+
const path = 'example.mdx'
445+
const value = await fs.readFile(path)
446+
-const MDXContent = (await evaluate({path, value}, runtime)).default
447+
+const MDXContent = (await evaluate({path, value}, {development: true, ...runtime})).default
448+
console.log(MDXContent({}))
462449
```
463450

464451
And we’d run it again, we’d get:
@@ -491,16 +478,12 @@ import {promises as fs} from 'node:fs'
491478
import {SourceMapGenerator} from 'source-map'
492479
import {compile} from '@mdx-js/mdx'
493480

494-
main()
495-
496-
async function main() {
497-
const file = await compile(
498-
{path: 'example.mdx', value: await fs.readFile('example.mdx')},
499-
{SourceMapGenerator}
500-
)
481+
const file = await compile(
482+
{path: 'example.mdx', value: await fs.readFile('example.mdx')},
483+
{SourceMapGenerator}
484+
)
501485

502-
console.log(file.map)
503-
}
486+
console.log(file.map)
504487
```
505488

506489
…yields:
@@ -724,12 +707,9 @@ import remarkPresetLintConsistent from 'remark-preset-lint-consistent' // Lint r
724707
import {reporter} from 'vfile-reporter'
725708
import {compile} from '@mdx-js/mdx'
726709

727-
main()
710+
const file = await compile('*like this* or _like this_?', {remarkPlugins: [remarkPresetLintConsistent]})
728711

729-
async function main() {
730-
const file = await compile('*like this* or _like this_?', {remarkPlugins: [remarkPresetLintConsistent]})
731-
console.error(reporter(file))
732-
}
712+
console.error(reporter(file))
733713
```
734714

735715
Yields:

0 commit comments

Comments
 (0)