Skip to content

Commit cace409

Browse files
authored
deps(marked): Update to v9 (from v4). (#118)
* Update. * Remove highlight. * Fix types.
1 parent cdafbf4 commit cace409

File tree

5 files changed

+89
-25
lines changed

5 files changed

+89
-25
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"devDependencies": {
1616
"@moonrepo/dev": "^2.0.1",
17-
"@types/marked": "^4.3.2",
17+
"@types/marked": "^6.0.0",
1818
"@types/react": "^18.2.33",
1919
"eslint": "^8.52.0",
2020
"eslint-config-moon": "^2.0.11",

packages/plugin/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
"@docusaurus/types": "^3.0.0",
5050
"@docusaurus/utils": "^3.0.0",
5151
"@vscode/codicons": "^0.0.35",
52-
"marked": "^4.3.0",
52+
"marked": "^9.1.4",
53+
"marked-smartypants": "^1.1.3",
5354
"typedoc": "0.25.0"
5455
},
5556
"devDependencies": {

packages/plugin/src/components/Markdown.tsx

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
/* eslint-disable react/no-array-index-key */
22

33
import { Fragment, useState } from 'react';
4-
import { marked } from 'marked';
4+
import { marked, type Tokens } from 'marked';
5+
import { markedSmartypants } from 'marked-smartypants';
56
import { useDocsData } from '@docusaurus/plugin-content-docs/client';
67
import { useDocsVersion } from '@docusaurus/theme-common/internal';
8+
import CodeBlock from '@theme/CodeBlock';
79
import MDX from '@theme/MDXComponents';
810
import { useReflectionMap } from '../hooks/useReflectionMap';
911
import { replaceLinkTokens } from '../utils/markdown';
@@ -14,22 +16,41 @@ interface Admonition {
1416
title?: string;
1517
keyword?: string;
1618
text: string;
17-
tokens: marked.Token[];
19+
tokens: Token[];
1820
}
1921

20-
type TokensList = (Admonition | marked.Token)[];
21-
22-
marked.setOptions({
23-
gfm: true,
24-
headerIds: false,
25-
mangle: false,
26-
smartLists: true,
27-
smartypants: true,
28-
});
22+
type Token =
23+
| Admonition
24+
| Tokens.Blockquote
25+
| Tokens.Br
26+
| Tokens.Code
27+
| Tokens.Codespan
28+
| Tokens.Def
29+
| Tokens.Del
30+
| Tokens.Em
31+
| Tokens.Escape
32+
| Tokens.Heading
33+
| Tokens.Hr
34+
| Tokens.HTML
35+
| Tokens.Image
36+
| Tokens.Link
37+
| Tokens.List
38+
| Tokens.ListItem
39+
| Tokens.Paragraph
40+
| Tokens.Space
41+
| Tokens.Strong
42+
| Tokens.Table
43+
| Tokens.Tag
44+
| Tokens.Text;
45+
type TokensList = Token[];
2946

3047
const ADMONITION_START = /^:{3}([a-z]+)? *(.*)\n/;
3148
const ADMONITION_END = '\n:::';
3249

50+
marked.setOptions({
51+
gfm: true,
52+
});
53+
marked.use(markedSmartypants());
3354
marked.use({
3455
extensions: [
3556
{
@@ -99,9 +120,12 @@ function convertAstToElements(ast: TokensList): React.ReactNode[] | undefined {
99120
switch (token.type) {
100121
case 'code':
101122
elements.push(
102-
<MDX.pre key={counter} className={token.lang && `language-${token.lang}`}>
123+
/* <MDX.pre key={counter} className={token.lang && `language-${token.lang}`}>
124+
{token.text}
125+
</MDX.pre>, */
126+
<CodeBlock key={counter} language={token.lang}>
103127
{token.text}
104-
</MDX.pre>,
128+
</CodeBlock>,
105129
);
106130
break;
107131

@@ -118,12 +142,12 @@ function convertAstToElements(ast: TokensList): React.ReactNode[] | undefined {
118142
}
119143

120144
case 'image':
121-
elements.push(<MDX.img key={counter} alt={token.title} src={token.href} />);
145+
elements.push(<MDX.img key={counter} alt={token.title ?? ''} src={token.href} />);
122146
break;
123147

124148
case 'link':
125149
elements.push(
126-
<MDX.a key={counter} href={token.href} title={token.title}>
150+
<MDX.a key={counter} href={token.href} title={token.title ?? ''}>
127151
{convertAstToElements(children) ?? token.text}
128152
</MDX.a>,
129153
);
@@ -231,8 +255,11 @@ export function Markdown({ content }: MarkdownProps) {
231255
const reflections = useReflectionMap();
232256
const version = useDocsVersion();
233257
const docsData = useDocsData(version.pluginId);
234-
const [ast] = useState<TokensList>(() =>
235-
marked.lexer(replaceLinkTokens(content, reflections, version, docsData.path)),
258+
const [ast] = useState<TokensList>(
259+
() =>
260+
marked.lexer(
261+
replaceLinkTokens(content, reflections, version, docsData.path),
262+
) as unknown as TokensList,
236263
);
237264

238265
if (!content) {

website/docusaurus.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ const config: Config = {
232232
prism: {
233233
theme: themes.github,
234234
darkTheme: themes.dracula,
235+
prism: {
236+
additionalLanguages: ['bash', 'diff', 'json', 'typescript'],
237+
},
235238
},
236239
},
237240
presets: [

yarn.lock

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4047,10 +4047,12 @@ __metadata:
40474047
languageName: node
40484048
linkType: hard
40494049

4050-
"@types/marked@npm:^4.3.2":
4051-
version: 4.3.2
4052-
resolution: "@types/marked@npm:4.3.2"
4053-
checksum: c1b5aa2cee0b8929164f4a8d206d7f89256ebde0d5b9998e9cdf6da2a5fa71162f66ef30e80b98213ee2c3372514b39b756e8494980174a4907a4aa4690b4d1d
4050+
"@types/marked@npm:^6.0.0":
4051+
version: 6.0.0
4052+
resolution: "@types/marked@npm:6.0.0"
4053+
dependencies:
4054+
marked: "npm:*"
4055+
checksum: ad4cd5a405604b27efb4d3979b05869f3069529d1f5b2a38039de7c96e57270f03e7580efe327ca1c136ec22a355d0a7d8578346bd2af8397fdd6bb76ca1b084
40544056
languageName: node
40554057
linkType: hard
40564058

@@ -7292,7 +7294,7 @@ __metadata:
72927294
resolution: "docusaurus-plugin-typedoc-api-root@workspace:."
72937295
dependencies:
72947296
"@moonrepo/dev": "npm:^2.0.1"
7295-
"@types/marked": "npm:^4.3.2"
7297+
"@types/marked": "npm:^6.0.0"
72967298
"@types/react": "npm:^18.2.33"
72977299
eslint: "npm:^8.52.0"
72987300
eslint-config-moon: "npm:^2.0.11"
@@ -7316,7 +7318,8 @@ __metadata:
73167318
"@docusaurus/types": "npm:^3.0.0"
73177319
"@docusaurus/utils": "npm:^3.0.0"
73187320
"@vscode/codicons": "npm:^0.0.35"
7319-
marked: "npm:^4.3.0"
7321+
marked: "npm:^9.1.4"
7322+
marked-smartypants: "npm:^1.1.3"
73207323
react: "npm:^18.2.0"
73217324
react-dom: "npm:^18.2.0"
73227325
typedoc: "npm:0.25.0"
@@ -11784,6 +11787,26 @@ __metadata:
1178411787
languageName: node
1178511788
linkType: hard
1178611789

11790+
"marked-smartypants@npm:^1.1.3":
11791+
version: 1.1.3
11792+
resolution: "marked-smartypants@npm:1.1.3"
11793+
dependencies:
11794+
smartypants: "npm:^0.2.2"
11795+
peerDependencies:
11796+
marked: ">=4 <10"
11797+
checksum: 1d9fa32f9adc4e91e31e34db96b02a9863ced5947766aec90816c8cd4cf396fcd1f76f1d80ef726988c313bbcf041b7ffb7770fbf4ced73b0069c151413356e0
11798+
languageName: node
11799+
linkType: hard
11800+
11801+
"marked@npm:*, marked@npm:^9.1.4":
11802+
version: 9.1.4
11803+
resolution: "marked@npm:9.1.4"
11804+
bin:
11805+
marked: bin/marked.js
11806+
checksum: 365d60f32818a01a7d7ff3baf3a860c28d65738e1dd3bb7645a339f6fda399cbfe13f06f0d156559f12b928998296a1b634834b729284d19b435bf0f2b26666b
11807+
languageName: node
11808+
linkType: hard
11809+
1178711810
"marked@npm:^4.3.0":
1178811811
version: 4.3.0
1178911812
resolution: "marked@npm:4.3.0"
@@ -16440,6 +16463,16 @@ __metadata:
1644016463
languageName: node
1644116464
linkType: hard
1644216465

16466+
"smartypants@npm:^0.2.2":
16467+
version: 0.2.2
16468+
resolution: "smartypants@npm:0.2.2"
16469+
bin:
16470+
smartypants: bin/smartypants.js
16471+
smartypantsu: bin/smartypantsu.js
16472+
checksum: e73ff0493fab65f8302d471cff01c1287d3d83ccbdd3d972c2bc383e2e65a51f6862429c0ce3efbafb6bad7cf4bb5648711567cb11465251aa273faee22626c0
16473+
languageName: node
16474+
linkType: hard
16475+
1644316476
"sockjs@npm:^0.3.24":
1644416477
version: 0.3.24
1644516478
resolution: "sockjs@npm:0.3.24"

0 commit comments

Comments
 (0)