Skip to content

Commit aaa122a

Browse files
authored
Merge pull request #38 from reactjs/sync-315cb7a3
2 parents 9bd0d50 + 53f26e3 commit aaa122a

File tree

4 files changed

+58
-9
lines changed

4 files changed

+58
-9
lines changed

plugins/remark-smartypants.js

+44-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*!
2+
* Based on 'silvenon/remark-smartypants'
3+
* https://github.com/silvenon/remark-smartypants/pull/80
4+
*/
5+
16
const visit = require('unist-util-visit');
27
const retext = require('retext');
38
const smartypants = require('retext-smartypants');
@@ -9,12 +14,48 @@ function check(parent) {
914
}
1015

1116
module.exports = function (options) {
12-
const processor = retext().use(smartypants, options);
17+
const processor = retext().use(smartypants, {
18+
...options,
19+
// Do not replace ellipses, dashes, backticks because they change string
20+
// length, and we couldn't guarantee right splice of text in second visit of
21+
// tree
22+
ellipses: false,
23+
dashes: false,
24+
backticks: false,
25+
});
26+
27+
const processor2 = retext().use(smartypants, {
28+
...options,
29+
// Do not replace quotes because they are already replaced in the first
30+
// processor
31+
quotes: false,
32+
});
1333

1434
function transformer(tree) {
15-
visit(tree, 'text', (node, index, parent) => {
16-
if (check(parent)) node.value = String(processor.processSync(node.value));
35+
let allText = '';
36+
let startIndex = 0;
37+
const textOrInlineCodeNodes = [];
38+
39+
visit(tree, ['text', 'inlineCode'], (node, _, parent) => {
40+
if (check(parent)) {
41+
if (node.type === 'text') allText += node.value;
42+
// for the case when inlineCode contains just one part of quote: `foo'bar`
43+
else allText += 'A'.repeat(node.value.length);
44+
textOrInlineCodeNodes.push(node);
45+
}
1746
});
47+
48+
// Concat all text into one string, to properly replace quotes around non-"text" nodes
49+
allText = String(processor.processSync(allText));
50+
51+
for (const node of textOrInlineCodeNodes) {
52+
const endIndex = startIndex + node.value.length;
53+
if (node.type === 'text') {
54+
const processedText = allText.slice(startIndex, endIndex);
55+
node.value = String(processor2.processSync(processedText));
56+
}
57+
startIndex = endIndex;
58+
}
1859
}
1960

2061
return transformer;

src/components/Layout/HomeContent.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -1499,7 +1499,7 @@ function ConferenceLayout({conf, children}) {
14991499
navigate(e.target.value);
15001500
});
15011501
}}
1502-
className="appearance-none pe-8 bg-transparent text-primary-dark text-2xl font-bold mb-0.5"
1502+
className="appearance-none pe-8 ps-2 bg-transparent text-primary-dark text-2xl font-bold mb-0.5"
15031503
style={{
15041504
backgroundSize: '4px 4px, 4px 4px',
15051505
backgroundRepeat: 'no-repeat',
@@ -1508,8 +1508,16 @@ function ConferenceLayout({conf, children}) {
15081508
backgroundImage:
15091509
'linear-gradient(45deg,transparent 50%,currentColor 50%),linear-gradient(135deg,currentColor 50%,transparent 50%)',
15101510
}}>
1511-
<option value="react-conf-2021">React Conf 2021</option>
1512-
<option value="react-conf-2019">React Conf 2019</option>
1511+
<option
1512+
className="bg-wash dark:bg-wash-dark text-primary dark:text-primary-dark"
1513+
value="react-conf-2021">
1514+
React Conf 2021
1515+
</option>
1516+
<option
1517+
className="bg-wash dark:bg-wash-dark text-primary dark:text-primary-dark"
1518+
value="react-conf-2019">
1519+
React Conf 2019
1520+
</option>
15131521
</select>
15141522
</Cover>
15151523
<div className="px-4 pb-4" key={conf.id}>

src/content/reference/react/use-server.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export default async function requestUsername(formData) {
153153
// UsernameForm.js
154154
'use client';
155155

156-
import {useFormState} from 'react-dom';
156+
import { useFormState } from 'react-dom';
157157
import requestUsername from './requestUsername';
158158

159159
function UsernameForm() {
@@ -208,7 +208,7 @@ function LikeButton() {
208208
'use server';
209209

210210
let likeCount = 0;
211-
export default async incrementLike() {
211+
export default async function incrementLike() {
212212
likeCount++;
213213
return likeCount;
214214
}

src/utils/prepareMDX.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {Children} from 'react';
77
// TODO: This logic could be in MDX plugins instead.
88

99
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10-
export const PREPARE_MDX_CACHE_BREAKER = 2;
10+
export const PREPARE_MDX_CACHE_BREAKER = 3;
1111
// !!! IMPORTANT !!! Bump this if you change any logic.
1212
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1313

0 commit comments

Comments
 (0)