Skip to content

Commit 2534424

Browse files
authored
fix: Stop SmartyPants from altering TerminalBlock commands (like --save-dev to —save-dev) (#8146)
* Skip smartypants on TerminalBlock * Improve TerminalBlock HTML tags * Remove unnecessary TerminalBlock escapes from docs * Bump DISK_CACHE_BREAKER
1 parent 27576f1 commit 2534424

File tree

6 files changed

+40
-20
lines changed

6 files changed

+40
-20
lines changed

plugins/remark-smartypants.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,24 @@ const visit = require('unist-util-visit');
1414
const retext = require('retext');
1515
const smartypants = require('retext-smartypants');
1616

17-
function check(parent) {
17+
function check(node, parent) {
18+
if (node.data?.skipSmartyPants) return false;
1819
if (parent.tagName === 'script') return false;
1920
if (parent.tagName === 'style') return false;
2021
return true;
2122
}
2223

24+
function markSkip(node) {
25+
if (!node) return;
26+
node.data ??= {};
27+
node.data.skipSmartyPants = true;
28+
if (Array.isArray(node.children)) {
29+
for (const child of node.children) {
30+
markSkip(child);
31+
}
32+
}
33+
}
34+
2335
module.exports = function (options) {
2436
const processor = retext().use(smartypants, {
2537
...options,
@@ -43,8 +55,14 @@ module.exports = function (options) {
4355
let startIndex = 0;
4456
const textOrInlineCodeNodes = [];
4557

58+
visit(tree, 'mdxJsxFlowElement', (node) => {
59+
if (['TerminalBlock'].includes(node.name)) {
60+
markSkip(node); // Mark all children to skip smarty pants
61+
}
62+
});
63+
4664
visit(tree, ['text', 'inlineCode'], (node, _, parent) => {
47-
if (check(parent)) {
65+
if (check(node, parent)) {
4866
if (node.type === 'text') allText += node.value;
4967
// for the case when inlineCode contains just one part of quote: `foo'bar`
5068
else allText += 'A'.repeat(node.value.length);

src/components/MDX/TerminalBlock.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,15 @@ function TerminalBlock({level = 'info', children}: TerminalBlockProps) {
7979
</div>
8080
</div>
8181
</div>
82-
<div
82+
<pre
8383
className="px-8 pt-4 pb-6 text-primary-dark dark:text-primary-dark font-mono text-code whitespace-pre overflow-x-auto"
8484
translate="no"
8585
dir="ltr">
86-
<LevelText type={level} />
87-
{message}
88-
</div>
86+
<code>
87+
<LevelText type={level} />
88+
{message}
89+
</code>
90+
</pre>
8991
</div>
9092
);
9193
}

src/content/blog/2025/10/07/react-compiler-1.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,17 @@ To install the compiler:
6969

7070
npm
7171
<TerminalBlock>
72-
{`npm install --save-dev --save-exact babel-plugin-react-compiler@latest`}
72+
npm install --save-dev --save-exact babel-plugin-react-compiler@latest
7373
</TerminalBlock>
7474

7575
pnpm
7676
<TerminalBlock>
77-
{`pnpm add --save-dev --save-exact babel-plugin-react-compiler@latest`}
77+
pnpm add --save-dev --save-exact babel-plugin-react-compiler@latest
7878
</TerminalBlock>
7979

8080
yarn
8181
<TerminalBlock>
82-
{`yarn add --dev --exact babel-plugin-react-compiler@latest`}
82+
yarn add --dev --exact babel-plugin-react-compiler@latest
8383
</TerminalBlock>
8484

8585
As part of the stable release, we've been making React Compiler easier to add to your projects and added optimizations to how the compiler generates memoization. React Compiler now supports optional chains and array indices as dependencies. These improvements ultimately result in fewer re-renders and more responsive UIs, while letting you keep writing idiomatic declarative code.
@@ -101,17 +101,17 @@ To install:
101101

102102
npm
103103
<TerminalBlock>
104-
{`npm install --save-dev eslint-plugin-react-hooks@latest`}
104+
npm install --save-dev eslint-plugin-react-hooks@latest
105105
</TerminalBlock>
106106

107107
pnpm
108108
<TerminalBlock>
109-
{`pnpm add --save-dev eslint-plugin-react-hooks@latest`}
109+
pnpm add --save-dev eslint-plugin-react-hooks@latest
110110
</TerminalBlock>
111111

112112
yarn
113113
<TerminalBlock>
114-
{`yarn add --dev eslint-plugin-react-hooks@latest`}
114+
yarn add --dev eslint-plugin-react-hooks@latest
115115
</TerminalBlock>
116116

117117
```js {6}
@@ -153,19 +153,19 @@ We have partnered with the Expo, Vite, and Next.js teams to add the compiler to
153153
[Expo SDK 54](https://docs.expo.dev/guides/react-compiler/) and up has the compiler enabled by default, so new apps will automatically be able to take advantage of the compiler from the start.
154154

155155
<TerminalBlock>
156-
{`npx create-expo-app@latest`}
156+
npx create-expo-app@latest
157157
</TerminalBlock>
158158

159159
[Vite](https://vite.dev/guide/) and [Next.js](https://nextjs.org/docs/app/api-reference/cli/create-next-app) users can choose the compiler enabled templates in `create-vite` and `create-next-app`.
160160

161161
<TerminalBlock>
162-
{`npm create vite@latest`}
162+
npm create vite@latest
163163
</TerminalBlock>
164164

165165
<br />
166166

167167
<TerminalBlock>
168-
{`npx create-next-app@latest`}
168+
npx create-next-app@latest
169169
</TerminalBlock>
170170

171171
## Adopt React Compiler incrementally {/*adopt-react-compiler-incrementally*/}

src/content/learn/build-a-react-app-from-scratch.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ The first step is to install a build tool like `vite`, `parcel`, or `rsbuild`. T
3434
[Vite](https://vite.dev/) is a build tool that aims to provide a faster and leaner development experience for modern web projects.
3535

3636
<TerminalBlock>
37-
{`npm create vite@latest my-app -- --template react-ts`}
37+
npm create vite@latest my-app -- --template react-ts
3838
</TerminalBlock>
3939

4040
Vite is opinionated and comes with sensible defaults out of the box. Vite has a rich ecosystem of plugins to support fast refresh, JSX, Babel/SWC, and other common features. See Vite's [React plugin](https://vite.dev/plugins/#vitejs-plugin-react) or [React SWC plugin](https://vite.dev/plugins/#vitejs-plugin-react-swc) and [React SSR example project](https://vite.dev/guide/ssr.html#example-projects) to get started.
@@ -46,7 +46,7 @@ Vite is already being used as a build tool in one of our [recommended frameworks
4646
[Parcel](https://parceljs.org/) combines a great out-of-the-box development experience with a scalable architecture that can take your project from just getting started to massive production applications.
4747

4848
<TerminalBlock>
49-
{`npm install --save-dev parcel`}
49+
npm install --save-dev parcel
5050
</TerminalBlock>
5151

5252
Parcel supports fast refresh, JSX, TypeScript, Flow, and styling out of the box. See [Parcel's React recipe](https://parceljs.org/recipes/react/#getting-started) to get started.
@@ -56,7 +56,7 @@ Parcel supports fast refresh, JSX, TypeScript, Flow, and styling out of the box.
5656
[Rsbuild](https://rsbuild.dev/) is an Rspack-powered build tool that provides a seamless development experience for React applications. It comes with carefully tuned defaults and performance optimizations ready to use.
5757

5858
<TerminalBlock>
59-
{`npx create-rsbuild --template react`}
59+
npx create-rsbuild --template react
6060
</TerminalBlock>
6161

6262
Rsbuild includes built-in support for React features like fast refresh, JSX, TypeScript, and styling. See [Rsbuild's React guide](https://rsbuild.dev/guide/framework/react) to get started.

src/content/learn/react-compiler/installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Please refer to the [Next.js docs](https://nextjs.org/docs/app/api-reference/nex
114114
Install `vite-plugin-babel`, and add the compiler's Babel plugin to it:
115115

116116
<TerminalBlock>
117-
{`npm install vite-plugin-babel`}
117+
npm install vite-plugin-babel
118118
</TerminalBlock>
119119

120120
```js {3-4,16}

src/utils/compileMDX.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {MDXComponents} from 'components/MDX/MDXComponents';
1010

1111
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1212
// ~~~~ IMPORTANT: BUMP THIS IF YOU CHANGE ANY CODE BELOW ~~~
13-
const DISK_CACHE_BREAKER = 10;
13+
const DISK_CACHE_BREAKER = 11;
1414
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1515

1616
export default async function compileMDX(

0 commit comments

Comments
 (0)