Skip to content

Commit 5a4f3e5

Browse files
committed
cleaner md
1 parent 97533a9 commit 5a4f3e5

File tree

5 files changed

+45
-16
lines changed

5 files changed

+45
-16
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"framer-motion": "^10.12.16",
6363
"github-slugger": "^2.0.0",
6464
"gray-matter": "^4.0.3",
65+
"hast-util-select": "^6.0.4",
6566
"hast-util-to-jsx-runtime": "^2.3.2",
6667
"hastscript": "^8.0.0",
6768
"image-size": "^1.2.1",
@@ -104,8 +105,7 @@
104105
"sharp": "^0.33.4",
105106
"tailwindcss-scoped-preflight": "^3.0.4",
106107
"textarea-markdown-editor": "^1.0.4",
107-
"unified": "^11.0.5",
108-
"unist-util-remove": "^4.0.0"
108+
"unified": "^11.0.5"
109109
},
110110
"devDependencies": {
111111
"@babel/preset-typescript": "^7.15.0",

scripts/generate-md-exports.mjs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/env node
22

3+
import {selectAll} from 'hast-util-select';
34
import {mkdir, opendir, readFile, rm, writeFile} from 'node:fs/promises';
45
import * as path from 'node:path';
56
import rehypeParse from 'rehype-parse';
67
import rehypeRemark from 'rehype-remark';
78
import remarkGfm from 'remark-gfm';
89
import remarkStringify from 'remark-stringify';
910
import {unified} from 'unified';
10-
import {remove} from 'unist-util-remove';
1111

1212
const root = process.cwd(); // fix this
1313
const INPUT_DIR = path.join(root, '.next', 'server', 'app');
@@ -20,8 +20,16 @@ export const genMDFromHTML = async (source, target) => {
2020
String(
2121
await unified()
2222
.use(rehypeParse)
23-
.use(rehypeRemark)
24-
.use(() => tree => remove(tree, {type: 'text', value: 'Copied'}))
23+
// Need the `main div > hgroup` selector for the headers
24+
.use(() => tree => selectAll('main div > hgroup, div#main', tree))
25+
// If we don't do this wrapping, rehypeRemark just returns an empty string -- yeah WTF?
26+
.use(() => tree => ({
27+
type: 'element',
28+
tagName: 'div',
29+
properties: {},
30+
children: tree,
31+
}))
32+
.use(rehypeRemark, {document: false})
2533
.use(remarkGfm)
2634
.use(remarkStringify)
2735
.process(text)
@@ -42,6 +50,7 @@ async function main() {
4250
// See https://github.com/nodejs/node/issues/48820
4351
const dir = await opendir(INPUT_DIR, {recursive: true, bufferSize: 1024});
4452
for await (const dirent of dir) {
53+
if (counter >= 100) break;
4554
if (dirent.name.endsWith('.html') && dirent.isFile()) {
4655
const sourcePath = path.join(dirent.parentPath || dirent.path, dirent.name);
4756
const targetDir = path.join(

src/components/apiExamples/apiExamples.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,11 @@ export function ApiExamples({api}: Props) {
129129
</button>
130130
</div>
131131
<pre className={`${styles['api-block-example']} relative`}>
132-
<div className={codeBlockStyles.copied} style={{opacity: showCopied ? 1 : 0}}>
132+
<div
133+
data-mdast="ignore"
134+
className={codeBlockStyles.copied}
135+
style={{opacity: showCopied ? 1 : 0}}
136+
>
133137
Copied
134138
</div>
135139
{selectedTabView === 0 &&

src/components/codeBlock/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ export function CodeBlock({filename, language, children}: CodeBlockProps) {
5555
</button>
5656
)}
5757
</div>
58-
<div className={styles.copied} style={{opacity: showCopied ? 1 : 0}}>
58+
<div
59+
data-mdast="ignore"
60+
className={styles.copied}
61+
style={{opacity: showCopied ? 1 : 0}}
62+
>
5963
Copied
6064
</div>
6165
<div ref={codeRef}>

yarn.lock

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7067,6 +7067,27 @@ hast-util-select@^6.0.0:
70677067
unist-util-visit "^5.0.0"
70687068
zwitch "^2.0.0"
70697069

7070+
hast-util-select@^6.0.4:
7071+
version "6.0.4"
7072+
resolved "https://registry.yarnpkg.com/hast-util-select/-/hast-util-select-6.0.4.tgz#1d8f69657a57441d0ce0ade35887874d3e65a303"
7073+
integrity sha512-RqGS1ZgI0MwxLaKLDxjprynNzINEkRHY2i8ln4DDjgv9ZhcYVIHN9rlpiYsqtFwrgpYU361SyWDQcGNIBVu3lw==
7074+
dependencies:
7075+
"@types/hast" "^3.0.0"
7076+
"@types/unist" "^3.0.0"
7077+
bcp-47-match "^2.0.0"
7078+
comma-separated-tokens "^2.0.0"
7079+
css-selector-parser "^3.0.0"
7080+
devlop "^1.0.0"
7081+
direction "^2.0.0"
7082+
hast-util-has-property "^3.0.0"
7083+
hast-util-to-string "^3.0.0"
7084+
hast-util-whitespace "^3.0.0"
7085+
nth-check "^2.0.0"
7086+
property-information "^7.0.0"
7087+
space-separated-tokens "^2.0.0"
7088+
unist-util-visit "^5.0.0"
7089+
zwitch "^2.0.0"
7090+
70707091
hast-util-to-estree@^2.0.0:
70717092
version "2.3.3"
70727093
resolved "https://registry.npmjs.org/hast-util-to-estree/-/hast-util-to-estree-2.3.3.tgz"
@@ -12381,15 +12402,6 @@ unist-util-remove-position@^4.0.0:
1238112402
"@types/unist" "^2.0.0"
1238212403
unist-util-visit "^4.0.0"
1238312404

12384-
unist-util-remove@^4.0.0:
12385-
version "4.0.0"
12386-
resolved "https://registry.yarnpkg.com/unist-util-remove/-/unist-util-remove-4.0.0.tgz#94b7d6bbd24e42d2f841e947ed087be5c82b222e"
12387-
integrity sha512-b4gokeGId57UVRX/eVKej5gXqGlc9+trkORhFJpu9raqZkZhU0zm8Doi05+HaiBsMEIJowL+2WtQ5ItjsngPXg==
12388-
dependencies:
12389-
"@types/unist" "^3.0.0"
12390-
unist-util-is "^6.0.0"
12391-
unist-util-visit-parents "^6.0.0"
12392-
1239312405
unist-util-stringify-position@^3.0.0:
1239412406
version "3.0.3"
1239512407
resolved "https://registry.npmjs.org/unist-util-stringify-position/-/unist-util-stringify-position-3.0.3.tgz"

0 commit comments

Comments
 (0)