@manuscripts/transform 2.0.1-LEAN-3092 → 2.0.2

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.
Files changed (47) hide show
  1. package/dist/cjs/index.js +1 -0
  2. package/dist/cjs/jats/importer/jats-body-dom-parser.js +72 -24
  3. package/dist/cjs/jats/jats-exporter.js +81 -28
  4. package/dist/cjs/mathjax/index.js +41 -0
  5. package/dist/cjs/mathjax/mathjax-packages.js +20 -0
  6. package/dist/cjs/mathjax/mathml-to-svg.js +70 -0
  7. package/dist/cjs/mathjax/tex-to-mathml.js +49 -0
  8. package/dist/cjs/mathjax/tex-to-svg.js +59 -0
  9. package/dist/cjs/schema/index.js +1 -0
  10. package/dist/cjs/schema/nodes/equation.js +14 -12
  11. package/dist/cjs/schema/nodes/equation_element.js +5 -4
  12. package/dist/cjs/schema/nodes/inline_equation.js +16 -12
  13. package/dist/cjs/transformer/builders.js +8 -1
  14. package/dist/cjs/transformer/decode.js +7 -4
  15. package/dist/cjs/transformer/encode.js +25 -4
  16. package/dist/cjs/transformer/node-types.js +1 -0
  17. package/dist/cjs/transformer/object-types.js +1 -0
  18. package/dist/es/index.js +1 -0
  19. package/dist/es/jats/importer/jats-body-dom-parser.js +73 -25
  20. package/dist/es/jats/jats-exporter.js +80 -28
  21. package/dist/es/mathjax/index.js +12 -0
  22. package/dist/es/mathjax/mathjax-packages.js +17 -0
  23. package/dist/es/mathjax/mathml-to-svg.js +66 -0
  24. package/dist/es/mathjax/tex-to-mathml.js +45 -0
  25. package/dist/es/mathjax/tex-to-svg.js +55 -0
  26. package/dist/es/schema/index.js +1 -0
  27. package/dist/es/schema/nodes/equation.js +14 -12
  28. package/dist/es/schema/nodes/equation_element.js +5 -4
  29. package/dist/es/schema/nodes/inline_equation.js +16 -12
  30. package/dist/es/transformer/builders.js +6 -0
  31. package/dist/es/transformer/decode.js +7 -4
  32. package/dist/es/transformer/encode.js +25 -4
  33. package/dist/es/transformer/node-types.js +1 -0
  34. package/dist/es/transformer/object-types.js +1 -0
  35. package/dist/types/index.d.ts +1 -0
  36. package/dist/types/jats/jats-exporter.d.ts +29 -2
  37. package/dist/types/mathjax/index.d.ts +3 -0
  38. package/dist/types/mathjax/mathjax-packages.d.ts +16 -0
  39. package/dist/types/mathjax/mathml-to-svg.d.ts +17 -0
  40. package/dist/types/mathjax/tex-to-mathml.d.ts +17 -0
  41. package/dist/types/mathjax/tex-to-svg.d.ts +17 -0
  42. package/dist/types/schema/index.d.ts +1 -0
  43. package/dist/types/schema/nodes/equation.d.ts +4 -3
  44. package/dist/types/schema/nodes/equation_element.d.ts +2 -1
  45. package/dist/types/schema/nodes/inline_equation.d.ts +4 -4
  46. package/dist/types/transformer/builders.d.ts +2 -1
  47. package/package.json +4 -2
package/dist/cjs/index.js CHANGED
@@ -18,6 +18,7 @@ exports.isSectionLabelNode = void 0;
18
18
  __exportStar(require("./lib/section-group-type"), exports);
19
19
  __exportStar(require("./lib/table-cell-styles"), exports);
20
20
  __exportStar(require("./lib/utils"), exports);
21
+ __exportStar(require("./mathjax"), exports);
21
22
  __exportStar(require("./schema"), exports);
22
23
  __exportStar(require("./transformer"), exports);
23
24
  __exportStar(require("./jats"), exports);
@@ -21,6 +21,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
21
21
  exports.jatsBodyDOMParser = void 0;
22
22
  const mime_1 = __importDefault(require("mime"));
23
23
  const prosemirror_model_1 = require("prosemirror-model");
24
+ const mathml_to_svg_1 = require("../../mathjax/mathml-to-svg");
25
+ const tex_to_svg_1 = require("../../mathjax/tex-to-svg");
24
26
  const schema_1 = require("../../schema");
25
27
  const transformer_1 = require("../../transformer");
26
28
  const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
@@ -37,24 +39,6 @@ const chooseContentType = (graphicNode) => {
37
39
  }
38
40
  }
39
41
  };
40
- const getEquationContent = (p) => {
41
- var _a;
42
- const element = p;
43
- const container = (_a = element.querySelector('alternatives')) !== null && _a !== void 0 ? _a : element;
44
- let contents = '';
45
- let format = '';
46
- for (const child of container.childNodes) {
47
- const nodeName = child.nodeName.replace(/^[a-z]:/, '');
48
- switch (nodeName) {
49
- case 'tex-math':
50
- case 'mml:math':
51
- contents = child.outerHTML;
52
- format = nodeName === 'tex-math' ? 'tex' : 'mathml';
53
- break;
54
- }
55
- }
56
- return { format, contents };
57
- };
58
42
  const marks = [
59
43
  {
60
44
  tag: 'bold',
@@ -163,27 +147,91 @@ const nodes = [
163
147
  tag: 'inline-formula',
164
148
  node: 'inline_equation',
165
149
  getAttrs: (node) => {
150
+ var _a, _b, _c, _d, _e;
166
151
  const element = node;
167
- return getEquationContent(element);
152
+ const attrs = {
153
+ id: element.getAttribute('id'),
154
+ MathMLRepresentation: '',
155
+ SVGRepresentation: '',
156
+ TeXRepresentation: '',
157
+ };
158
+ const container = (_a = element.querySelector('alternatives')) !== null && _a !== void 0 ? _a : element;
159
+ for (const child of container.childNodes) {
160
+ const nodeName = child.nodeName.replace(/^[a-z]:/, '');
161
+ switch (nodeName) {
162
+ case 'tex-math':
163
+ attrs.TeXRepresentation = (_c = (_b = child.textContent) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : '';
164
+ if (attrs.TeXRepresentation) {
165
+ attrs.SVGRepresentation =
166
+ (_d = (0, tex_to_svg_1.convertTeXToSVG)(attrs.TeXRepresentation, true)) !== null && _d !== void 0 ? _d : '';
167
+ }
168
+ break;
169
+ case 'mml:math':
170
+ ;
171
+ child.removeAttribute('id');
172
+ attrs.MathMLRepresentation = transformer_1.xmlSerializer.serializeToString(child);
173
+ if (attrs.MathMLRepresentation) {
174
+ attrs.SVGRepresentation =
175
+ (_e = (0, mathml_to_svg_1.convertMathMLToSVG)(attrs.MathMLRepresentation, true)) !== null && _e !== void 0 ? _e : '';
176
+ }
177
+ break;
178
+ }
179
+ }
180
+ return attrs;
168
181
  },
169
182
  },
170
183
  {
171
184
  tag: 'disp-formula',
172
185
  node: 'equation_element',
173
186
  getAttrs: (node) => {
174
- var _a, _b;
175
187
  const element = node;
188
+ const caption = element.querySelector('figcaption');
176
189
  return {
177
190
  id: element.getAttribute('id'),
178
- label: (_b = (_a = element.querySelector('label')) === null || _a === void 0 ? void 0 : _a.textContent) !== null && _b !== void 0 ? _b : '',
191
+ suppressCaption: !caption,
179
192
  };
180
193
  },
181
194
  getContent: (node, schema) => {
195
+ var _a, _b, _c, _d, _e;
182
196
  const element = node;
183
- const attrs = getEquationContent(element);
184
- const id = element.getAttribute('id');
197
+ const attrs = {
198
+ MathMLStringRepresentation: '',
199
+ SVGStringRepresentation: '',
200
+ TeXRepresentation: '',
201
+ };
202
+ const container = (_a = element.querySelector('alternatives')) !== null && _a !== void 0 ? _a : element;
203
+ for (const child of container.childNodes) {
204
+ const nodeName = child.nodeName.replace(/^[a-z]:/, '');
205
+ switch (nodeName) {
206
+ case 'tex-math':
207
+ attrs.TeXRepresentation = (_c = (_b = child.textContent) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : '';
208
+ if (attrs.TeXRepresentation) {
209
+ attrs.SVGStringRepresentation =
210
+ (_d = (0, tex_to_svg_1.convertTeXToSVG)(attrs.TeXRepresentation, true)) !== null && _d !== void 0 ? _d : '';
211
+ }
212
+ break;
213
+ case 'mml:math':
214
+ ;
215
+ child.removeAttribute('id');
216
+ attrs.MathMLStringRepresentation =
217
+ transformer_1.xmlSerializer.serializeToString(child);
218
+ if (attrs.MathMLStringRepresentation) {
219
+ attrs.SVGStringRepresentation =
220
+ (_e = (0, mathml_to_svg_1.convertMathMLToSVG)(attrs.MathMLStringRepresentation, true)) !== null && _e !== void 0 ? _e : '';
221
+ }
222
+ break;
223
+ }
224
+ }
225
+ const caption = element.querySelector('figcaption');
226
+ const figcaption = schema.nodes.figcaption.create();
185
227
  return prosemirror_model_1.Fragment.from([
186
- schema.nodes.equation.createChecked(Object.assign({ id }, attrs)),
228
+ schema.nodes.equation.createChecked(attrs),
229
+ caption
230
+ ?
231
+ exports.jatsBodyDOMParser.parse(caption, {
232
+ topNode: figcaption,
233
+ })
234
+ : figcaption,
187
235
  ]);
188
236
  },
189
237
  },
@@ -18,8 +18,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
18
18
  return (mod && mod.__esModule) ? mod : { "default": mod };
19
19
  };
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.JATSExporter = exports.createCounter = void 0;
21
+ exports.JATSExporter = exports.buildCitations = exports.createCounter = void 0;
22
22
  const json_schema_1 = require("@manuscripts/json-schema");
23
+ const library_1 = require("@manuscripts/library");
23
24
  const debug_1 = __importDefault(require("debug"));
24
25
  const prosemirror_model_1 = require("prosemirror-model");
25
26
  const w3c_xmlserializer_1 = __importDefault(require("w3c-xmlserializer"));
@@ -115,12 +116,23 @@ const chooseRefType = (objectType) => {
115
116
  }
116
117
  };
117
118
  const sortContributors = (a, b) => Number(a.priority) - Number(b.priority);
119
+ const buildCitations = (citations) => citations.map((citation) => ({
120
+ citationID: citation.attrs.id,
121
+ citationItems: citation.attrs.rids.map((rid) => ({
122
+ id: rid,
123
+ })),
124
+ properties: {
125
+ noteIndex: 0,
126
+ },
127
+ }));
128
+ exports.buildCitations = buildCitations;
118
129
  class JATSExporter {
119
130
  constructor() {
120
- this.serializeToJATS = async (fragment, modelMap, manuscriptID, options = {}) => {
121
- const { version = '1.2', doi, id, frontMatterOnly = false, links, idGenerator, mediaPathGenerator, } = options;
131
+ this.serializeToJATS = async (fragment, modelMap, manuscriptID, options) => {
132
+ const { version = '1.2', doi, id, frontMatterOnly = false, links, idGenerator, mediaPathGenerator, csl, } = options;
122
133
  this.modelMap = modelMap;
123
134
  this.models = Array.from(this.modelMap.values());
135
+ this.generateCitationTexts(fragment, csl);
124
136
  this.createSerializer();
125
137
  const versionIds = (0, jats_versions_1.selectVersionIds)(version);
126
138
  this.document = document.implementation.createDocument(null, 'article', document.implementation.createDocumentType('article', versionIds.publicId, versionIds.systemId));
@@ -152,7 +164,6 @@ class JATSExporter {
152
164
  };
153
165
  this.nodeFromJATS = (JATSFragment) => {
154
166
  JATSFragment = JATSFragment.trim();
155
- JATSFragment = JATSFragment.replace(' ', ' ');
156
167
  if (!JATSFragment.length) {
157
168
  return null;
158
169
  }
@@ -463,10 +474,11 @@ class JATSExporter {
463
474
  refList = this.document.createElement('ref-list');
464
475
  }
465
476
  back.appendChild(refList);
466
- const bibliographyItems = this.models.filter((0, object_types_1.hasObjectType)(json_schema_1.ObjectTypes.BibliographyItem));
467
- for (const bibliographyItem of bibliographyItems) {
477
+ const [meta] = this.citationProvider.makeBibliography();
478
+ for (const id of meta.entry_ids) {
479
+ const bibliographyItem = this.modelMap.get(id[0]);
468
480
  const ref = this.document.createElement('ref');
469
- ref.setAttribute('id', normalizeID(bibliographyItem._id));
481
+ ref.setAttribute('id', normalizeID(id[0]));
470
482
  const updateCitationPubType = (citationEl, pubType) => {
471
483
  if (pubType) {
472
484
  switch (pubType) {
@@ -639,12 +651,11 @@ class JATSExporter {
639
651
  const xref = this.document.createElement('xref');
640
652
  xref.setAttribute('ref-type', 'bibr');
641
653
  xref.setAttribute('rid', normalizeID(rids.join(' ')));
642
- if (citation.attrs.contents) {
643
- const text = (0, html_1.textFromHTML)(node.attrs.contents);
644
- if (text !== null && text.length) {
645
- xref.textContent = text;
646
- }
654
+ const citationTextContent = this.citationTexts.get(node.attrs.id);
655
+ if (!citationTextContent) {
656
+ throw new Error(`No citation text found for ${node.attrs.id}`);
647
657
  }
658
+ xref.textContent = (0, html_1.textFromHTML)(citationTextContent);
648
659
  return xref;
649
660
  },
650
661
  cross_reference: (node) => {
@@ -673,23 +684,22 @@ class JATSExporter {
673
684
  },
674
685
  doc: () => '',
675
686
  equation: (node) => {
676
- const math = this.nodeFromJATS(node.attrs.contents);
677
- const mathEl = math;
678
- mathEl.setAttribute('id', normalizeID(node.attrs.id));
679
- return mathEl;
680
- },
681
- inline_equation: (node) => {
682
- const eqElement = this.document.createElement('inline-formula');
683
- const math = this.nodeFromJATS(node.attrs.contents);
684
- eqElement.append(math);
685
- return eqElement;
686
- },
687
- equation_element: (node) => {
688
- const eqElement = this.document.createElement('disp-formula');
689
- eqElement.setAttribute('id', normalizeID(node.attrs.id));
690
- processChildNodes(eqElement, node, schema_1.schema.nodes.equation);
691
- return eqElement;
687
+ const formula = this.document.createElement('disp-formula');
688
+ formula.setAttribute('id', normalizeID(node.attrs.id));
689
+ if (node.attrs.TeXRepresentation) {
690
+ const math = this.document.createElement('tex-math');
691
+ math.textContent = node.attrs.TeXRepresentation;
692
+ formula.appendChild(math);
693
+ }
694
+ else if (node.attrs.MathMLStringRepresentation) {
695
+ const math = this.nodeFromJATS(node.attrs.MathMLStringRepresentation);
696
+ if (math) {
697
+ formula.appendChild(math);
698
+ }
699
+ }
700
+ return formula;
692
701
  },
702
+ equation_element: (node) => createFigureElement(node, 'fig', node.type.schema.nodes.equation, 'equation'),
693
703
  figcaption: (node) => {
694
704
  if (!node.textContent) {
695
705
  return '';
@@ -739,6 +749,28 @@ class JATSExporter {
739
749
  },
740
750
  hard_break: () => '',
741
751
  highlight_marker: () => '',
752
+ inline_equation: (node) => {
753
+ const formula = this.document.createElement('inline-formula');
754
+ formula.setAttribute('id', normalizeID(node.attrs.id));
755
+ if (node.attrs.TeXRepresentation) {
756
+ const math = this.document.createElement('tex-math');
757
+ math.textContent = node.attrs.TeXRepresentation;
758
+ formula.appendChild(math);
759
+ }
760
+ else if (node.attrs.MathMLRepresentation) {
761
+ const math = this.nodeFromJATS(node.attrs.MathMLRepresentation);
762
+ if (math) {
763
+ formula.appendChild(math);
764
+ }
765
+ }
766
+ else if (node.attrs.SVGRepresentation) {
767
+ const math = this.nodeFromJATS(node.attrs.SVGRepresentation);
768
+ if (math) {
769
+ formula.appendChild(math);
770
+ }
771
+ }
772
+ return formula;
773
+ },
742
774
  inline_footnote: (node) => {
743
775
  const xref = this.document.createElement('xref');
744
776
  xref.setAttribute('ref-type', 'fn');
@@ -1534,6 +1566,27 @@ class JATSExporter {
1534
1566
  return name;
1535
1567
  };
1536
1568
  }
1569
+ generateCitations(fragment) {
1570
+ const nodes = [];
1571
+ fragment.descendants((node) => {
1572
+ if ((0, schema_1.isCitationNode)(node)) {
1573
+ nodes.push(node);
1574
+ }
1575
+ });
1576
+ return (0, exports.buildCitations)(nodes);
1577
+ }
1578
+ generateCitationTexts(fragment, csl) {
1579
+ this.citationTexts = new Map();
1580
+ this.citationProvider = new library_1.CitationProvider({
1581
+ getLibraryItem: (id) => this.modelMap.get(id),
1582
+ locale: csl.locale,
1583
+ citationStyle: csl.style,
1584
+ });
1585
+ const citations = this.generateCitations(fragment);
1586
+ this.citationProvider.rebuildState(citations).forEach(([id, , output]) => {
1587
+ this.citationTexts.set(id, output);
1588
+ });
1589
+ }
1537
1590
  buildKeywords(articleMeta) {
1538
1591
  const keywords = [...this.modelMap.values()].filter((model) => model.objectType === json_schema_1.ObjectTypes.Keyword);
1539
1592
  const keywordGroups = new Map();
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.convertTeXToSVG = exports.convertTeXToMathML = exports.convertMathMLToSVG = void 0;
27
+ const convertMathMLToSVG = async (mathml, display) => {
28
+ const { convertMathMLToSVG } = await Promise.resolve().then(() => __importStar(require('./mathml-to-svg')));
29
+ return convertMathMLToSVG(mathml, display);
30
+ };
31
+ exports.convertMathMLToSVG = convertMathMLToSVG;
32
+ const convertTeXToMathML = async (tex, display) => {
33
+ const { convertTeXToMathML } = await Promise.resolve().then(() => __importStar(require('./tex-to-mathml')));
34
+ return convertTeXToMathML(tex, display);
35
+ };
36
+ exports.convertTeXToMathML = convertTeXToMathML;
37
+ const convertTeXToSVG = async (tex, display) => {
38
+ const { convertTeXToSVG } = await Promise.resolve().then(() => __importStar(require('./tex-to-svg')));
39
+ return convertTeXToSVG(tex, display);
40
+ };
41
+ exports.convertTeXToSVG = convertTeXToSVG;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2019 Atypon Systems LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.packages = void 0;
19
+ const AllPackages_1 = require("mathjax-full/js/input/tex/AllPackages");
20
+ exports.packages = AllPackages_1.AllPackages.filter((name) => name !== 'html' && name !== 'bussproofs');
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2019 Atypon Systems LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.convertMathMLToSVG = void 0;
19
+ require("mathjax-full/js/util/entities/all");
20
+ const HTMLAdaptor_1 = require("mathjax-full/js/adaptors/HTMLAdaptor");
21
+ const MmlFactory_1 = require("mathjax-full/js/core/MmlTree/MmlFactory");
22
+ const HTMLDocument_1 = require("mathjax-full/js/handlers/html/HTMLDocument");
23
+ const mathml_1 = require("mathjax-full/js/input/mathml");
24
+ const svg_1 = require("mathjax-full/js/output/svg");
25
+ const transformer_1 = require("../transformer");
26
+ class ManuscriptsMmlFactory extends MmlFactory_1.MmlFactory {
27
+ constructor() {
28
+ super();
29
+ this.nodeMap.set('image', this.nodeMap.get('none'));
30
+ }
31
+ create(kind, properties = {}, children = []) {
32
+ if (kind === 'image') {
33
+ return this.node['none'](properties, children);
34
+ }
35
+ return this.node[kind](properties, children);
36
+ }
37
+ }
38
+ class ManuscriptsHTMLAdaptor extends HTMLAdaptor_1.HTMLAdaptor {
39
+ setAttribute(node, name, value, ns) {
40
+ if (name !== 'xmlns') {
41
+ ns ? node.setAttributeNS(ns, name, value) : node.setAttribute(name, value);
42
+ }
43
+ }
44
+ }
45
+ const InputJax = new mathml_1.MathML();
46
+ const OutputJax = new svg_1.SVG({
47
+ fontCache: 'none',
48
+ });
49
+ const adaptor = new ManuscriptsHTMLAdaptor(window);
50
+ const doc = new HTMLDocument_1.HTMLDocument(document, adaptor, {
51
+ InputJax,
52
+ OutputJax,
53
+ MmlFactory: new ManuscriptsMmlFactory(),
54
+ });
55
+ doc.addStyleSheet();
56
+ const convertMathMLToSVG = (mathml, display) => {
57
+ const item = doc.convert(mathml, {
58
+ display,
59
+ em: 16,
60
+ ex: 8,
61
+ containerWidth: 1000000,
62
+ lineWidth: 1000000,
63
+ scale: 1,
64
+ });
65
+ if (!item || !item.firstChild) {
66
+ return null;
67
+ }
68
+ return transformer_1.xmlSerializer.serializeToString(item.firstChild);
69
+ };
70
+ exports.convertMathMLToSVG = convertMathMLToSVG;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2019 Atypon Systems LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.convertTeXToMathML = void 0;
19
+ require("mathjax-full/js/util/entities/all");
20
+ const HTMLAdaptor_1 = require("mathjax-full/js/adaptors/HTMLAdaptor");
21
+ const MathItem_js_1 = require("mathjax-full/js/core/MathItem.js");
22
+ const SerializedMmlVisitor_1 = require("mathjax-full/js/core/MmlTree/SerializedMmlVisitor");
23
+ const HTMLDocument_1 = require("mathjax-full/js/handlers/html/HTMLDocument");
24
+ const tex_1 = require("mathjax-full/js/input/tex");
25
+ const mathjax_packages_1 = require("./mathjax-packages");
26
+ const InputJax = new tex_1.TeX({
27
+ packages: mathjax_packages_1.packages,
28
+ });
29
+ const adaptor = new HTMLAdaptor_1.HTMLAdaptor(window);
30
+ const doc = new HTMLDocument_1.HTMLDocument(document, adaptor, {
31
+ InputJax,
32
+ });
33
+ const visitor = new SerializedMmlVisitor_1.SerializedMmlVisitor();
34
+ const convertTeXToMathML = (tex, display) => {
35
+ const item = doc.convert(tex, {
36
+ display,
37
+ em: 16,
38
+ ex: 8,
39
+ containerWidth: 1000000,
40
+ lineWidth: 1000000,
41
+ scale: 1,
42
+ end: MathItem_js_1.STATE.CONVERT,
43
+ });
44
+ if (!item) {
45
+ return null;
46
+ }
47
+ return visitor.visitTree(item);
48
+ };
49
+ exports.convertTeXToMathML = convertTeXToMathML;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2019 Atypon Systems LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.convertTeXToSVG = void 0;
19
+ require("mathjax-full/js/util/entities/all");
20
+ const HTMLAdaptor_1 = require("mathjax-full/js/adaptors/HTMLAdaptor");
21
+ const HTMLDocument_1 = require("mathjax-full/js/handlers/html/HTMLDocument");
22
+ const tex_1 = require("mathjax-full/js/input/tex");
23
+ const svg_1 = require("mathjax-full/js/output/svg");
24
+ const transformer_1 = require("../transformer");
25
+ const mathjax_packages_1 = require("./mathjax-packages");
26
+ class ManuscriptsHTMLAdaptor extends HTMLAdaptor_1.HTMLAdaptor {
27
+ setAttribute(node, name, value, ns) {
28
+ if (name !== 'xmlns') {
29
+ ns ? node.setAttributeNS(ns, name, value) : node.setAttribute(name, value);
30
+ }
31
+ }
32
+ }
33
+ const InputJax = new tex_1.TeX({
34
+ packages: mathjax_packages_1.packages,
35
+ });
36
+ const OutputJax = new svg_1.SVG({
37
+ fontCache: 'none',
38
+ });
39
+ const adaptor = new ManuscriptsHTMLAdaptor(window);
40
+ const doc = new HTMLDocument_1.HTMLDocument(document, adaptor, {
41
+ InputJax,
42
+ OutputJax,
43
+ });
44
+ doc.addStyleSheet();
45
+ const convertTeXToSVG = (tex, display) => {
46
+ const item = doc.convert(tex, {
47
+ display,
48
+ em: 16,
49
+ ex: 8,
50
+ containerWidth: 1000000,
51
+ lineWidth: 1000000,
52
+ scale: 1,
53
+ });
54
+ if (!item || !item.firstChild) {
55
+ return null;
56
+ }
57
+ return transformer_1.xmlSerializer.serializeToString(item.firstChild);
58
+ };
59
+ exports.convertTeXToSVG = convertTeXToSVG;
@@ -115,6 +115,7 @@ __exportStar(require("./nodes/footnotes_section"), exports);
115
115
  __exportStar(require("./nodes/graphical_abstract_section"), exports);
116
116
  __exportStar(require("./nodes/hard_break"), exports);
117
117
  __exportStar(require("./nodes/highlight_marker"), exports);
118
+ __exportStar(require("./nodes/inline_equation"), exports);
118
119
  __exportStar(require("./nodes/inline_footnote"), exports);
119
120
  __exportStar(require("./nodes/keyword"), exports);
120
121
  __exportStar(require("./nodes/keywords_element"), exports);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*!
3
- * © 2023 Atypon Systems LLC
3
+ * © 2019 Atypon Systems LLC
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -20,8 +20,9 @@ const json_schema_1 = require("@manuscripts/json-schema");
20
20
  exports.equation = {
21
21
  attrs: {
22
22
  id: { default: '' },
23
- contents: { default: '' },
24
- format: { default: '' },
23
+ MathMLStringRepresentation: { default: '' },
24
+ SVGStringRepresentation: { default: '' },
25
+ TeXRepresentation: { default: '' },
25
26
  dataTracked: { default: null },
26
27
  },
27
28
  group: 'block',
@@ -29,25 +30,26 @@ exports.equation = {
29
30
  {
30
31
  tag: `div.${json_schema_1.ObjectTypes.Equation}`,
31
32
  getAttrs: (p) => {
32
- const htmlEl = p;
33
+ const dom = p;
33
34
  return {
34
- id: htmlEl.getAttribute('id'),
35
- format: htmlEl.getAttribute('data-equation-format'),
36
- contents: htmlEl.innerHTML,
35
+ id: dom.getAttribute('id'),
36
+ MathMLStringRepresentation: dom.getAttribute('data-mathml-string-representation'),
37
+ SVGStringRepresentation: dom.innerHTML,
38
+ TeXRepresentation: dom.getAttribute('data-tex-representation'),
37
39
  };
38
40
  },
39
41
  },
40
42
  ],
41
43
  toDOM: (node) => {
42
44
  const equationNode = node;
43
- const { id, contents, format } = equationNode.attrs;
44
45
  const dom = document.createElement('div');
46
+ dom.setAttribute('id', equationNode.attrs.id);
45
47
  dom.classList.add(json_schema_1.ObjectTypes.Equation);
46
- dom.setAttribute('id', id);
47
- if (format) {
48
- dom.setAttribute('data-equation-format', format);
48
+ if (equationNode.attrs.MathMLStringRepresentation) {
49
+ dom.setAttribute('data-mathml-string-representation', equationNode.attrs.MathMLStringRepresentation);
49
50
  }
50
- dom.innerHTML = contents;
51
+ dom.setAttribute('data-tex-representation', equationNode.attrs.TeXRepresentation);
52
+ dom.innerHTML = equationNode.attrs.SVGStringRepresentation;
51
53
  return dom;
52
54
  },
53
55
  };
@@ -17,10 +17,11 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.equationElement = void 0;
19
19
  exports.equationElement = {
20
- content: '(equation | placeholder)',
20
+ content: '(equation | placeholder) figcaption',
21
21
  attrs: {
22
22
  id: { default: '' },
23
- label: { default: '' },
23
+ suppressCaption: { default: true },
24
+ suppressTitle: { default: undefined },
24
25
  dataTracked: { default: null },
25
26
  comments: { default: null },
26
27
  },
@@ -28,7 +29,7 @@ exports.equationElement = {
28
29
  group: 'block element',
29
30
  parseDOM: [
30
31
  {
31
- tag: 'div.equation',
32
+ tag: 'figure.equation',
32
33
  getAttrs: (p) => {
33
34
  const dom = p;
34
35
  return {
@@ -40,7 +41,7 @@ exports.equationElement = {
40
41
  toDOM: (node) => {
41
42
  const equationElementNode = node;
42
43
  return [
43
- 'div',
44
+ 'figure',
44
45
  {
45
46
  class: 'equation',
46
47
  id: equationElementNode.attrs.id,