myst-to-react 0.1.16 → 0.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/basic.tsx +12 -5
- package/src/card.tsx +15 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "myst-to-react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"main": "./src/index.tsx",
|
|
5
5
|
"types": "./src/index.tsx",
|
|
6
6
|
"files": [
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"ansi-to-react": "^6.1.6",
|
|
24
24
|
"buffer": "^6.0.3",
|
|
25
25
|
"classnames": "^2.3.1",
|
|
26
|
-
"mermaid": "^9.1.
|
|
26
|
+
"mermaid": "^9.1.7",
|
|
27
27
|
"myst-spec": "^0.0.4",
|
|
28
28
|
"myst-to-docx": "*",
|
|
29
29
|
"myst-to-tex": "*",
|
package/src/basic.tsx
CHANGED
|
@@ -203,11 +203,18 @@ const BASIC_RENDERERS: BasicNodeRenderers = {
|
|
|
203
203
|
return <dl key={node.key}>{children}</dl>;
|
|
204
204
|
},
|
|
205
205
|
definitionTerm(node, children) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
206
|
+
let strongChildren: React.ReactNode = children;
|
|
207
|
+
if (Array.isArray(children)) {
|
|
208
|
+
const allowedStrongTypes = new Set(['emphasis']);
|
|
209
|
+
strongChildren = children.map((child, i) => {
|
|
210
|
+
if (typeof child === 'string') return <strong key={node.key + i}>{child}</strong>;
|
|
211
|
+
if (allowedStrongTypes.has(child?.type)) return <strong key={node.key + i}>{child}</strong>;
|
|
212
|
+
return child;
|
|
213
|
+
});
|
|
214
|
+
} else if (typeof children === 'string') {
|
|
215
|
+
strongChildren = <strong key={node.key + '0'}>{children}</strong>;
|
|
216
|
+
}
|
|
217
|
+
return <dt key={node.key}>{strongChildren}</dt>;
|
|
211
218
|
},
|
|
212
219
|
definitionDescription(node, children) {
|
|
213
220
|
return <dd key={node.key}>{children}</dd>;
|
package/src/card.tsx
CHANGED
|
@@ -7,6 +7,7 @@ import { Link } from '@remix-run/react';
|
|
|
7
7
|
type CardSpec = {
|
|
8
8
|
type: 'card';
|
|
9
9
|
url?: string;
|
|
10
|
+
static?: boolean;
|
|
10
11
|
};
|
|
11
12
|
type CardTitleSpec = {
|
|
12
13
|
type: 'cardTitle';
|
|
@@ -71,15 +72,17 @@ function getParts(children: React.ReactNode): Parts {
|
|
|
71
72
|
function ExternalOrInternalLink({
|
|
72
73
|
to,
|
|
73
74
|
className,
|
|
75
|
+
isStatic,
|
|
74
76
|
prefetch = 'intent',
|
|
75
77
|
children,
|
|
76
78
|
}: {
|
|
77
79
|
to: string;
|
|
78
80
|
className?: string;
|
|
81
|
+
isStatic?: boolean;
|
|
79
82
|
prefetch?: 'intent' | 'render' | 'none';
|
|
80
83
|
children: React.ReactNode;
|
|
81
84
|
}) {
|
|
82
|
-
if (to.startsWith('http')) {
|
|
85
|
+
if (to.startsWith('http') || isStatic) {
|
|
83
86
|
return (
|
|
84
87
|
<a href={to} className={className} target="_blank" rel="noopener noreferrer">
|
|
85
88
|
{children}
|
|
@@ -93,7 +96,15 @@ function ExternalOrInternalLink({
|
|
|
93
96
|
);
|
|
94
97
|
}
|
|
95
98
|
|
|
96
|
-
function Card({
|
|
99
|
+
function Card({
|
|
100
|
+
children,
|
|
101
|
+
url,
|
|
102
|
+
isStatic,
|
|
103
|
+
}: {
|
|
104
|
+
children: React.ReactNode;
|
|
105
|
+
url?: string;
|
|
106
|
+
isStatic?: boolean;
|
|
107
|
+
}) {
|
|
97
108
|
const parts = getParts(children);
|
|
98
109
|
const link = !!url;
|
|
99
110
|
const sharedStyle =
|
|
@@ -102,6 +113,7 @@ function Card({ children, url }: { children: React.ReactNode; url?: string }) {
|
|
|
102
113
|
return (
|
|
103
114
|
<ExternalOrInternalLink
|
|
104
115
|
to={url}
|
|
116
|
+
isStatic={isStatic}
|
|
105
117
|
className={classNames(
|
|
106
118
|
sharedStyle,
|
|
107
119
|
'block font-normal no-underline cursor-pointer group',
|
|
@@ -125,7 +137,7 @@ function Card({ children, url }: { children: React.ReactNode; url?: string }) {
|
|
|
125
137
|
|
|
126
138
|
export const CardRenderer: NodeRenderer<CardSpec> = (node, children) => {
|
|
127
139
|
return (
|
|
128
|
-
<Card key={node.key} url={node.url}>
|
|
140
|
+
<Card key={node.key} url={node.url} isStatic={node.static || false}>
|
|
129
141
|
{children}
|
|
130
142
|
</Card>
|
|
131
143
|
);
|