myst-demo 0.6.1 → 0.8.0

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.
@@ -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;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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":";AAiBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAgN1D,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
@@ -9,7 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
11
11
  import { VFile } from 'vfile';
12
+ import { remove } from 'unist-util-remove';
12
13
  import yaml from 'js-yaml';
14
+ import { fileError, RuleId, } from 'myst-common';
13
15
  import { SourceFileKind } from 'myst-spec-ext';
14
16
  import { validatePageFrontmatter } from 'myst-frontmatter';
15
17
  import { ReferencesProvider } from '@myst-theme/providers';
@@ -37,14 +39,45 @@ function saveDocxFile(filename, mdast) {
37
39
  downloadBlob(filename, docxBlob);
38
40
  });
39
41
  }
42
+ /**
43
+ * Simpler function than getFrontmatter from myst-transforms
44
+ *
45
+ * This only strips frontmatter yaml; it does nothing with headings
46
+ */
47
+ function getFrontmatter(vfile, tree) {
48
+ var _a, _b;
49
+ const firstParent = ((_a = tree.children[0]) === null || _a === void 0 ? void 0 : _a.type) === 'block' ? tree.children[0] : tree;
50
+ const firstNode = (_b = firstParent.children) === null || _b === void 0 ? void 0 : _b[0];
51
+ let frontmatter = {};
52
+ const firstIsYaml = (firstNode === null || firstNode === void 0 ? void 0 : firstNode.type) === 'code' && (firstNode === null || firstNode === void 0 ? void 0 : firstNode.lang) === 'yaml';
53
+ if (firstIsYaml) {
54
+ try {
55
+ frontmatter = yaml.load(firstNode.value) || {};
56
+ firstNode.type = '__delete__';
57
+ }
58
+ catch (err) {
59
+ fileError(vfile, 'Invalid YAML frontmatter', {
60
+ note: err.message,
61
+ ruleId: RuleId.frontmatterIsYaml,
62
+ });
63
+ }
64
+ }
65
+ // Handles deleting the block if it is the only element in the block
66
+ const possibleNull = remove(tree, '__delete__');
67
+ if (possibleNull === null) {
68
+ // null is returned if tree itself didn’t pass the test or is cascaded away
69
+ remove(tree, { cascade: false }, '__delete__');
70
+ }
71
+ return frontmatter;
72
+ }
40
73
  function parse(text, defaultFrontmatter, options) {
41
- var _a, _b, _c, _d;
74
+ var _a, _b, _c;
42
75
  return __awaiter(this, void 0, void 0, function* () {
43
76
  // Ensure that any imports from myst are async and scoped to this function
44
77
  const { visit } = yield import('unist-util-visit');
45
78
  const { unified } = yield import('unified');
46
79
  const { mystParse } = yield import('myst-parser');
47
- const { mathPlugin, footnotesPlugin, keysPlugin, basicTransformationsPlugin, enumerateTargetsPlugin, resolveReferencesPlugin, WikiTransformer, GithubTransformer, DOITransformer, RRIDTransformer, linksPlugin, ReferenceState, getFrontmatter, abbreviationPlugin, glossaryPlugin, joinGatesPlugin, } = yield import('myst-transforms');
80
+ const { mathPlugin, footnotesPlugin, keysPlugin, basicTransformationsPlugin, enumerateTargetsPlugin, resolveReferencesPlugin, WikiTransformer, GithubTransformer, DOITransformer, RRIDTransformer, linksPlugin, ReferenceState, abbreviationPlugin, glossaryPlugin, joinGatesPlugin, } = yield import('myst-transforms');
48
81
  const { default: mystToTex } = yield import('myst-to-tex');
49
82
  const { default: mystToTypst } = yield import('myst-to-typst');
50
83
  const { default: mystToJats } = yield import('myst-to-jats').catch(() => ({ default: null }));
@@ -54,7 +87,7 @@ function parse(text, defaultFrontmatter, options) {
54
87
  const { tabDirectives } = yield import('myst-ext-tabs');
55
88
  const { proofDirective } = yield import('myst-ext-proof');
56
89
  const { exerciseDirectives } = yield import('myst-ext-exercise');
57
- const file = new VFile();
90
+ const vfile = new VFile();
58
91
  const parseMyst = (content) => mystParse(content, {
59
92
  markdownit: { linkify: true },
60
93
  directives: [
@@ -65,7 +98,7 @@ function parse(text, defaultFrontmatter, options) {
65
98
  ...exerciseDirectives,
66
99
  ],
67
100
  // roles: [reactiveRole],
68
- vfile: file,
101
+ vfile,
69
102
  });
70
103
  const mdast = parseMyst(text);
71
104
  const linkTransforms = [
@@ -83,17 +116,14 @@ function parse(text, defaultFrontmatter, options) {
83
116
  cite: { order: [], data: {} },
84
117
  footnotes: {},
85
118
  };
86
- const { frontmatter: frontmatterRaw } = getFrontmatter(file, mdast, {
87
- removeYaml: true,
88
- removeHeading: (_a = options === null || options === void 0 ? void 0 : options.removeHeading) !== null && _a !== void 0 ? _a : false,
89
- });
119
+ const frontmatterRaw = getFrontmatter(vfile, mdast);
90
120
  const frontmatter = validatePageFrontmatter(frontmatterRaw, {
91
121
  property: 'frontmatter',
92
122
  messages: {},
93
123
  });
94
- const state = new ReferenceState({
95
- numbering: (_b = frontmatter.numbering) !== null && _b !== void 0 ? _b : defaultFrontmatter === null || defaultFrontmatter === void 0 ? void 0 : defaultFrontmatter.numbering,
96
- file,
124
+ const state = new ReferenceState('', {
125
+ numbering: (_a = frontmatter.numbering) !== null && _a !== void 0 ? _a : defaultFrontmatter === null || defaultFrontmatter === void 0 ? void 0 : defaultFrontmatter.numbering,
126
+ vfile,
97
127
  });
98
128
  visit(mdast, (n) => {
99
129
  // Before we put in the citation render, we can mark them as errors
@@ -103,8 +133,8 @@ function parse(text, defaultFrontmatter, options) {
103
133
  });
104
134
  unified()
105
135
  .use(basicTransformationsPlugin, { parser: parseMyst })
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
107
- .use(glossaryPlugin, { state }) // This should be before the enumerate plugins
136
+ .use(mathPlugin, { macros: (_b = frontmatter === null || frontmatter === void 0 ? void 0 : frontmatter.math) !== null && _b !== void 0 ? _b : {} }) // This must happen before enumeration, as it can add labels
137
+ .use(glossaryPlugin) // This should be before the enumerate plugins
108
138
  .use(abbreviationPlugin, { abbreviations: frontmatter.abbreviations })
109
139
  .use(enumerateTargetsPlugin, { state })
110
140
  .use(linksPlugin, { transformers: linkTransforms })
@@ -112,7 +142,7 @@ function parse(text, defaultFrontmatter, options) {
112
142
  .use(joinGatesPlugin)
113
143
  .use(resolveReferencesPlugin, { state })
114
144
  .use(keysPlugin)
115
- .runSync(mdast, file);
145
+ .runSync(mdast, vfile);
116
146
  const mdastPost = JSON.parse(JSON.stringify(mdast));
117
147
  visit(mdastPost, (n) => {
118
148
  delete n.position;
@@ -142,7 +172,7 @@ function parse(text, defaultFrontmatter, options) {
142
172
  ? unified()
143
173
  .use(mystToJats, SourceFileKind.Article, frontmatter, undefined, '', {
144
174
  format: 2,
145
- writeFullArticle: (_d = options === null || options === void 0 ? void 0 : options.jats) === null || _d === void 0 ? void 0 : _d.fullArticle,
175
+ writeFullArticle: (_c = options === null || options === void 0 ? void 0 : options.jats) === null || _c === void 0 ? void 0 : _c.fullArticle,
146
176
  })
147
177
  .stringify(mdast, jatsFile).result
148
178
  : 'Problem loading myst-to-jats';
@@ -158,7 +188,7 @@ function parse(text, defaultFrontmatter, options) {
158
188
  typstWarnings: typstFile.messages,
159
189
  jats: jats,
160
190
  jatsWarnings: jatsFile.messages,
161
- warnings: file.messages,
191
+ warnings: vfile.messages,
162
192
  };
163
193
  });
164
194
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "myst-demo",
3
- "version": "0.6.1",
3
+ "version": "0.8.0",
4
4
  "type": "module",
5
5
  "exports": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -23,25 +23,26 @@
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.18",
27
- "myst-config": "^1.1.18",
28
- "myst-directives": "^1.0.18",
29
- "myst-ext-card": "^1.0.4",
30
- "myst-ext-exercise": "^1.0.4",
31
- "myst-ext-grid": "^1.0.4",
32
- "myst-ext-proof": "^1.0.6",
33
- "myst-ext-tabs": "^1.0.4",
34
- "myst-frontmatter": "^1.1.18",
35
- "myst-parser": "^1.0.18",
36
- "myst-spec": "^0.0.4",
37
- "myst-to-docx": "^1.0.7",
38
- "myst-to-html": "^1.0.18",
39
- "myst-to-jats": "^1.0.19",
40
- "myst-to-react": "^0.6.1",
41
- "myst-to-tex": "^1.0.14",
42
- "myst-to-typst": "^0.0.6",
43
- "myst-transforms": "^1.1.16",
26
+ "myst-common": "^1.1.31",
27
+ "myst-config": "^1.1.31",
28
+ "myst-directives": "^1.2.0",
29
+ "myst-ext-card": "^1.0.5",
30
+ "myst-ext-exercise": "^1.0.5",
31
+ "myst-ext-grid": "^1.0.5",
32
+ "myst-ext-proof": "^1.0.8",
33
+ "myst-ext-tabs": "^1.0.5",
34
+ "myst-frontmatter": "^1.1.31",
35
+ "myst-parser": "^1.2.0",
36
+ "myst-spec": "^0.0.5",
37
+ "myst-to-docx": "^1.0.9",
38
+ "myst-to-html": "^1.2.0",
39
+ "myst-to-jats": "^1.0.24",
40
+ "myst-to-react": "^0.8.0",
41
+ "myst-to-tex": "^1.0.23",
42
+ "myst-to-typst": "^0.0.12",
43
+ "myst-transforms": "^1.3.1",
44
44
  "unified": "^10.1.2",
45
+ "unist-util-remove": "^4.0.0",
45
46
  "unist-util-visit": "^4.1.2",
46
47
  "vfile": "^5.3.7",
47
48
  "vfile-message": "^3.1.4"