myst-demo 0.5.13 → 0.5.15
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/dist/index.d.ts.map +1 -1
- package/dist/index.js +39 -13
- package/package.json +11 -11
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":";AASA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":";AASA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAsL1D,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,MAAM,EACN,UAAU,EACV,SAAS,EACT,UAAU,EACV,UAAU,EACV,SAAS,GACV,EAAE;IACD,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,WAAW,EAAE,eAAe,CAAA;KAAE,KAAK,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC;IAC7E,SAAS,CAAC,EAAE,GAAG,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,2CA6PA;AAED,eAAO,MAAM,gBAAgB,EAAE,YAE9B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -55,7 +55,7 @@ function parse(text, defaultFrontmatter, options) {
|
|
|
55
55
|
const { proofDirective } = yield import('myst-ext-proof');
|
|
56
56
|
const { exerciseDirectives } = yield import('myst-ext-exercise');
|
|
57
57
|
const file = new VFile();
|
|
58
|
-
const
|
|
58
|
+
const parseMyst = (content) => mystParse(content, {
|
|
59
59
|
markdownit: { linkify: true },
|
|
60
60
|
directives: [
|
|
61
61
|
cardDirective,
|
|
@@ -67,6 +67,7 @@ function parse(text, defaultFrontmatter, options) {
|
|
|
67
67
|
// roles: [reactiveRole],
|
|
68
68
|
vfile: file,
|
|
69
69
|
});
|
|
70
|
+
const mdast = parseMyst(text);
|
|
70
71
|
const linkTransforms = [
|
|
71
72
|
new WikiTransformer(),
|
|
72
73
|
new GithubTransformer(),
|
|
@@ -76,10 +77,8 @@ function parse(text, defaultFrontmatter, options) {
|
|
|
76
77
|
// For the mdast that we show, duplicate, strip positions and dump to yaml
|
|
77
78
|
// Also run some of the transforms, like the links
|
|
78
79
|
const mdastPre = JSON.parse(JSON.stringify(mdast));
|
|
79
|
-
unified().use(linksPlugin, { transformers: linkTransforms }).runSync(mdastPre);
|
|
80
80
|
visit(mdastPre, (n) => delete n.position);
|
|
81
|
-
const
|
|
82
|
-
const htmlString = mystToHtml(mdastPre);
|
|
81
|
+
const htmlString = mystToHtml(JSON.parse(JSON.stringify(mdast)));
|
|
83
82
|
const references = {
|
|
84
83
|
cite: { order: [], data: {} },
|
|
85
84
|
footnotes: {},
|
|
@@ -96,8 +95,14 @@ function parse(text, defaultFrontmatter, options) {
|
|
|
96
95
|
numbering: (_b = frontmatter.numbering) !== null && _b !== void 0 ? _b : defaultFrontmatter === null || defaultFrontmatter === void 0 ? void 0 : defaultFrontmatter.numbering,
|
|
97
96
|
file,
|
|
98
97
|
});
|
|
98
|
+
visit(mdast, (n) => {
|
|
99
|
+
// Before we put in the citation render, we can mark them as errors
|
|
100
|
+
if (n.type === 'cite') {
|
|
101
|
+
n.error = true;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
99
104
|
unified()
|
|
100
|
-
.use(basicTransformationsPlugin)
|
|
105
|
+
.use(basicTransformationsPlugin, { parser: parseMyst })
|
|
101
106
|
.use(mathPlugin, { macros: (_c = frontmatter === null || frontmatter === void 0 ? void 0 : frontmatter.math) !== null && _c !== void 0 ? _c : {} }) // This must happen before enumeration, as it can add labels
|
|
102
107
|
.use(glossaryPlugin, { state }) // This should be before the enumerate plugins
|
|
103
108
|
.use(abbreviationPlugin, { abbreviations: frontmatter.abbreviations })
|
|
@@ -108,6 +113,11 @@ function parse(text, defaultFrontmatter, options) {
|
|
|
108
113
|
.use(resolveReferencesPlugin, { state })
|
|
109
114
|
.use(keysPlugin)
|
|
110
115
|
.runSync(mdast, file);
|
|
116
|
+
const mdastPost = JSON.parse(JSON.stringify(mdast));
|
|
117
|
+
visit(mdastPost, (n) => {
|
|
118
|
+
delete n.position;
|
|
119
|
+
delete n.key;
|
|
120
|
+
});
|
|
111
121
|
const texFile = new VFile();
|
|
112
122
|
const tex = unified()
|
|
113
123
|
.use(mystToTex, { references })
|
|
@@ -138,7 +148,8 @@ function parse(text, defaultFrontmatter, options) {
|
|
|
138
148
|
: 'Problem loading myst-to-jats';
|
|
139
149
|
return {
|
|
140
150
|
frontmatter,
|
|
141
|
-
|
|
151
|
+
mdastPre,
|
|
152
|
+
mdastPost,
|
|
142
153
|
references: Object.assign(Object.assign({}, references), { article: mdast }),
|
|
143
154
|
html: htmlString,
|
|
144
155
|
tex: tex.value,
|
|
@@ -157,7 +168,8 @@ export function MySTRenderer({ value, column, fullscreen, numbering, TitleBlock,
|
|
|
157
168
|
const [text, setText] = useState(value.trim());
|
|
158
169
|
const [references, setReferences] = useState({});
|
|
159
170
|
const [frontmatter, setFrontmatter] = useState({});
|
|
160
|
-
const [
|
|
171
|
+
const [mdastPre, setMdastPre] = useState('Loading...');
|
|
172
|
+
const [mdastPost, setMdastPost] = useState('Loading...');
|
|
161
173
|
const [html, setHtml] = useState('Loading...');
|
|
162
174
|
const [tex, setTex] = useState('Loading...');
|
|
163
175
|
const [texWarnings, setTexWarnings] = useState([]);
|
|
@@ -167,13 +179,16 @@ export function MySTRenderer({ value, column, fullscreen, numbering, TitleBlock,
|
|
|
167
179
|
const [jatsWarnings, setJatsWarnings] = useState([]);
|
|
168
180
|
const [warnings, setWarnings] = useState([]);
|
|
169
181
|
const [previewType, setPreviewType] = useState('DEMO');
|
|
182
|
+
const [astLang, setAstLang] = useState('yaml');
|
|
183
|
+
const [astStage, setAstStage] = useState('pre');
|
|
170
184
|
useEffect(() => {
|
|
171
185
|
const ref = { current: true };
|
|
172
186
|
parse(text, { numbering }, { removeHeading: !!TitleBlock, jats: { fullArticle: !!TitleBlock } }).then((result) => {
|
|
173
187
|
if (!ref.current)
|
|
174
188
|
return;
|
|
175
189
|
setFrontmatter(result.frontmatter);
|
|
176
|
-
|
|
190
|
+
setMdastPre(result.mdastPre);
|
|
191
|
+
setMdastPost(result.mdastPost);
|
|
177
192
|
setReferences(result.references);
|
|
178
193
|
setHtml(result.html);
|
|
179
194
|
setTex(result.tex);
|
|
@@ -226,17 +241,28 @@ export function MySTRenderer({ value, column, fullscreen, numbering, TitleBlock,
|
|
|
226
241
|
default:
|
|
227
242
|
break;
|
|
228
243
|
}
|
|
229
|
-
const demoMenu = (_jsx("div", { className: "self-center text-sm border cursor-pointer dark:border-slate-600", children: ['DEMO', 'AST', 'HTML', 'LaTeX', 'Typst', 'JATS', 'DOCX'].map((show) => (_jsx("button", { className: classnames('px-2 py-1', {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
244
|
+
const demoMenu = (_jsxs(_Fragment, { children: [_jsx("div", { className: "self-center text-sm border cursor-pointer dark:border-slate-600", children: ['DEMO', 'AST', 'HTML', 'LaTeX', 'Typst', 'JATS', 'DOCX'].map((show) => (_jsx("button", { className: classnames('px-2 py-1', {
|
|
245
|
+
'bg-white hover:bg-slate-200 dark:bg-slate-500 dark:hover:bg-slate-700': previewType !== show,
|
|
246
|
+
'bg-blue-800 text-white': previewType === show,
|
|
247
|
+
}), title: `Show the ${show}`, "aria-label": `Show the ${show}`, "aria-pressed": previewType === show ? 'true' : 'false', onClick: () => setPreviewType(show), children: show }, show))) }), previewType === 'AST' && (_jsxs("div", { className: "self-center text-sm border cursor-pointer w-fit dark:border-slate-600", children: [['yaml', 'json'].map((show) => (_jsx("button", { className: classnames('px-2 py-1', {
|
|
248
|
+
'bg-white hover:bg-slate-200 dark:bg-slate-500 dark:hover:bg-slate-700': astLang !== show,
|
|
249
|
+
'bg-blue-800 text-white': astLang === show,
|
|
250
|
+
}), title: `Show the AST as ${show.toUpperCase()}`, "aria-pressed": astLang === show ? 'true' : 'false', onClick: () => setAstLang(show), children: show.toUpperCase() }, show))), ['pre', 'post'].map((show) => (_jsx("button", { className: classnames('px-2 py-1', {
|
|
251
|
+
'bg-white hover:bg-slate-200 dark:bg-slate-500 dark:hover:bg-slate-700': astStage !== show,
|
|
252
|
+
'bg-blue-800 text-white': astStage === show,
|
|
253
|
+
}), title: `Show the AST Stage ${show.toUpperCase()}`, "aria-pressed": astStage === show ? 'true' : 'false', onClick: () => setAstStage(show), children: show.toUpperCase() }, show)))] }))] }));
|
|
254
|
+
const mdastStage = astStage === 'pre' ? mdastPre : mdastPost;
|
|
233
255
|
return (_jsxs("figure", { className: classnames('relative', {
|
|
234
256
|
'grid grid-cols-2 gap-0 grid-rows-[3rem_1fr]': column,
|
|
235
257
|
'shadow-lg rounded': !fullscreen,
|
|
236
258
|
'm-0': fullscreen,
|
|
237
259
|
}, className), children: [column && (_jsxs("div", { className: "flex flex-row items-stretch h-full col-span-2 px-2 border dark:border-slate-600", children: [_jsx("div", { className: "flex-grow" }), demoMenu] })), _jsxs("div", { className: classnames('myst relative', { 'overflow-auto': column }), children: [_jsx(CopyIcon, { text: text, className: "absolute right-0 p-1" }), _jsxs("label", { children: [_jsx("span", { className: "sr-only", children: "Edit the MyST Markdown text" }), _jsx("textarea", { ref: area, value: text, className: classnames('block p-6 shadow-inner resize-none w-full font-mono bg-slate-50/50 dark:bg-slate-800/50 outline-none', { 'text-sm': !column }, { 'h-full': column }), onChange: (e) => setText(e.target.value) })] })] }), _jsxs("div", { className: classnames('exclude-from-outline relative min-h-1 dark:bg-slate-900', {
|
|
238
260
|
'overflow-auto': column,
|
|
239
|
-
}), children: [!column && _jsx("div", { className: "absolute top-0 left-0", children: demoMenu }), _jsxs("div", { className: classnames('px-6 pb-6', {
|
|
261
|
+
}), children: [!column && _jsx("div", { className: "absolute top-0 left-0", children: demoMenu }), _jsxs("div", { className: classnames('px-6 pb-6', {
|
|
262
|
+
'pt-[40px]': !column && previewType !== 'AST',
|
|
263
|
+
'pt-[80px]': !column && previewType === 'AST',
|
|
264
|
+
'pt-4': column,
|
|
265
|
+
}), children: [previewType === 'DEMO' && (_jsx(_Fragment, { children: _jsxs(ReferencesProvider, { references: references, frontmatter: frontmatter, children: [TitleBlock && _jsx(TitleBlock, { frontmatter: frontmatter }), _jsx(MyST, { ast: (_a = references.article) === null || _a === void 0 ? void 0 : _a.children })] }) })), previewType === 'AST' && (_jsx(_Fragment, { children: _jsx(CodeBlock, { lang: astLang, value: astLang === 'yaml' ? yaml.dump(mdastStage) : JSON.stringify(mdastStage, null, 2) }) })), previewType === 'HTML' && _jsx(CodeBlock, { lang: "xml", value: html, showCopy: false }), previewType === 'LaTeX' && _jsx(CodeBlock, { lang: "latex", value: tex, showCopy: false }), previewType === 'Typst' && _jsx(CodeBlock, { lang: "typst", value: typst, showCopy: false }), previewType === 'JATS' && _jsx(CodeBlock, { lang: "xml", value: jats, showCopy: false }), previewType === 'DOCX' && (_jsx("div", { children: _jsxs("button", { className: "p-3 border rounded", onClick: () => saveDocxFile('demo.docx', references.article), title: `Download Micorsoft Word`, "aria-label": `Download Micorsoft Word`, children: [_jsx(ArrowDownTrayIcon, { width: "1.3rem", height: "1.3rem", className: "inline mr-1" }), ' ', "Download as Microsoft Word"] }) }))] }), currentWarnings.length > 0 && (_jsx("div", { className: classnames('w-full', { 'absolute bottom-0': column }), children: currentWarnings.map((m, i) => (_jsxs("div", { className: classnames('p-1 shadow-inner text-white not-prose', {
|
|
240
266
|
'bg-red-500 dark:bg-red-800': m.fatal === true,
|
|
241
267
|
'bg-orange-500 dark:bg-orange-700': m.fatal === false,
|
|
242
268
|
'bg-slate-500 dark:bg-slate-800': m.fatal === null,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "myst-demo",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.15",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -23,24 +23,24 @@
|
|
|
23
23
|
"@heroicons/react": "^2.0.18",
|
|
24
24
|
"classnames": "^2.3.2",
|
|
25
25
|
"js-yaml": "^4.1.0",
|
|
26
|
-
"myst-common": "^1.1.
|
|
27
|
-
"myst-config": "^1.1.
|
|
28
|
-
"myst-directives": "^1.0.
|
|
26
|
+
"myst-common": "^1.1.15",
|
|
27
|
+
"myst-config": "^1.1.15",
|
|
28
|
+
"myst-directives": "^1.0.16",
|
|
29
29
|
"myst-ext-card": "^1.0.4",
|
|
30
30
|
"myst-ext-exercise": "^1.0.4",
|
|
31
31
|
"myst-ext-grid": "^1.0.4",
|
|
32
32
|
"myst-ext-proof": "^1.0.6",
|
|
33
33
|
"myst-ext-tabs": "^1.0.4",
|
|
34
|
-
"myst-frontmatter": "^1.1.
|
|
35
|
-
"myst-parser": "^1.0.
|
|
34
|
+
"myst-frontmatter": "^1.1.15",
|
|
35
|
+
"myst-parser": "^1.0.16",
|
|
36
36
|
"myst-spec": "^0.0.4",
|
|
37
37
|
"myst-to-docx": "^1.0.7",
|
|
38
|
-
"myst-to-html": "^1.0.
|
|
39
|
-
"myst-to-jats": "^1.0.
|
|
40
|
-
"myst-to-react": "^0.5.
|
|
41
|
-
"myst-to-tex": "^1.0.
|
|
38
|
+
"myst-to-html": "^1.0.16",
|
|
39
|
+
"myst-to-jats": "^1.0.18",
|
|
40
|
+
"myst-to-react": "^0.5.15",
|
|
41
|
+
"myst-to-tex": "^1.0.14",
|
|
42
42
|
"myst-to-typst": "^0.0.6",
|
|
43
|
-
"myst-transforms": "^1.1.
|
|
43
|
+
"myst-transforms": "^1.1.13",
|
|
44
44
|
"unified": "^10.1.2",
|
|
45
45
|
"unist-util-visit": "^4.1.2",
|
|
46
46
|
"vfile": "^5.3.7",
|