Skip to content

Commit

Permalink
Merge pull request #622 from reactjs/sync-315cb7a3
Browse files Browse the repository at this point in the history
Sync with react.dev @ 315cb7a
  • Loading branch information
tdd authored Jan 10, 2024
2 parents 5f73037 + fe7f752 commit 7821f08
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 10 deletions.
47 changes: 44 additions & 3 deletions plugins/remark-smartypants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*!
* Based on 'silvenon/remark-smartypants'
* https://github.com/silvenon/remark-smartypants/pull/80
*/

const visit = require('unist-util-visit');
const retext = require('retext');
const smartypants = require('retext-smartypants');
Expand All @@ -9,12 +14,48 @@ function check(parent) {
}

module.exports = function (options) {
const processor = retext().use(smartypants, options);
const processor = retext().use(smartypants, {
...options,
// Do not replace ellipses, dashes, backticks because they change string
// length, and we couldn't guarantee right splice of text in second visit of
// tree
ellipses: false,
dashes: false,
backticks: false,
});

const processor2 = retext().use(smartypants, {
...options,
// Do not replace quotes because they are already replaced in the first
// processor
quotes: false,
});

function transformer(tree) {
visit(tree, 'text', (node, index, parent) => {
if (check(parent)) node.value = String(processor.processSync(node.value));
let allText = '';
let startIndex = 0;
const textOrInlineCodeNodes = [];

visit(tree, ['text', 'inlineCode'], (node, _, parent) => {
if (check(parent)) {
if (node.type === 'text') allText += node.value;
// for the case when inlineCode contains just one part of quote: `foo'bar`
else allText += 'A'.repeat(node.value.length);
textOrInlineCodeNodes.push(node);
}
});

// Concat all text into one string, to properly replace quotes around non-"text" nodes
allText = String(processor.processSync(allText));

for (const node of textOrInlineCodeNodes) {
const endIndex = startIndex + node.value.length;
if (node.type === 'text') {
const processedText = allText.slice(startIndex, endIndex);
node.value = String(processor2.processSync(processedText));
}
startIndex = endIndex;
}
}

return transformer;
Expand Down
14 changes: 11 additions & 3 deletions src/components/Layout/HomeContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,7 @@ function ConferenceLayout({conf, children}) {
navigate(e.target.value);
});
}}
className="appearance-none pe-8 bg-transparent text-primary-dark text-2xl font-bold mb-0.5"
className="appearance-none pe-8 ps-2 bg-transparent text-primary-dark text-2xl font-bold mb-0.5"
style={{
backgroundSize: '4px 4px, 4px 4px',
backgroundRepeat: 'no-repeat',
Expand All @@ -1526,8 +1526,16 @@ function ConferenceLayout({conf, children}) {
backgroundImage:
'linear-gradient(45deg,transparent 50%,currentColor 50%),linear-gradient(135deg,currentColor 50%,transparent 50%)',
}}>
<option value="react-conf-2021">React Conf 2021</option>
<option value="react-conf-2019">React Conf 2019</option>
<option
className="bg-wash dark:bg-wash-dark text-primary dark:text-primary-dark"
value="react-conf-2021">
React Conf 2021
</option>
<option
className="bg-wash dark:bg-wash-dark text-primary dark:text-primary-dark"
value="react-conf-2019">
React Conf 2019
</option>
</select>
</Cover>
<div className="px-4 pb-4" key={conf.id}>
Expand Down
5 changes: 2 additions & 3 deletions src/content/reference/react/use-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export default async function requestUsername(formData) {
// UsernameForm.js
'use client';

import {useFormState} from 'react-dom';
import { useFormState } from 'react-dom';
import requestUsername from './requestUsername';

function UsernameForm() {
Expand Down Expand Up @@ -208,8 +208,7 @@ function LikeButton() {
'use server';

let likeCount = 0;

export default async incrementLike() {
export default async function incrementLike() {
likeCount++;
return likeCount;
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/prepareMDX.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {Children} from 'react';
// TODO: This logic could be in MDX plugins instead.

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export const PREPARE_MDX_CACHE_BREAKER = 2;
export const PREPARE_MDX_CACHE_BREAKER = 3;
// !!! IMPORTANT !!! Bump this if you change any logic.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down

0 comments on commit 7821f08

Please sign in to comment.