@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
@@ -16,39 +16,43 @@
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.inlineEquation = void 0;
19
+ const json_schema_1 = require("@manuscripts/json-schema");
19
20
  exports.inlineEquation = {
20
21
  attrs: {
22
+ id: { default: '' },
23
+ MathMLRepresentation: { default: '' },
24
+ SVGRepresentation: { default: '' },
25
+ TeXRepresentation: { default: '' },
21
26
  dataTracked: { default: null },
22
- comments: { default: null },
23
- contents: { default: '' },
24
- format: { default: '' },
25
27
  },
26
- selectable: false,
27
28
  atom: true,
28
29
  inline: true,
29
30
  draggable: true,
30
31
  group: 'inline',
31
32
  parseDOM: [
32
33
  {
33
- tag: `span.MPInlineMathFragment`,
34
+ tag: `span.${json_schema_1.ObjectTypes.InlineMathFragment}`,
34
35
  getAttrs: (p) => {
35
36
  const dom = p;
36
37
  return {
37
- format: dom.getAttribute('data-equation-format'),
38
- contents: dom.innerHTML,
38
+ id: dom.getAttribute('id'),
39
+ MathMLRepresentation: dom.getAttribute('data-mathml-representation') || '',
40
+ SVGRepresentation: dom.innerHTML || '',
41
+ TeXRepresentation: dom.getAttribute('data-tex-representation') || '',
39
42
  };
40
43
  },
41
44
  },
42
45
  ],
43
46
  toDOM: (node) => {
44
47
  const inlineEquationNode = node;
45
- const { contents, format } = inlineEquationNode.attrs;
46
48
  const dom = document.createElement('span');
47
- dom.classList.add('MPInlineMathFragment');
48
- if (format) {
49
- dom.setAttribute('data-equation-format', format);
49
+ dom.classList.add(json_schema_1.ObjectTypes.InlineMathFragment);
50
+ dom.setAttribute('id', inlineEquationNode.attrs.id);
51
+ dom.setAttribute('data-tex-representation', inlineEquationNode.attrs.TeXRepresentation);
52
+ if (inlineEquationNode.attrs.MathMLRepresentation) {
53
+ dom.setAttribute('data-mathml-representation', inlineEquationNode.attrs.MathMLRepresentation);
50
54
  }
51
- dom.innerHTML = contents;
55
+ dom.innerHTML = inlineEquationNode.attrs.SVGRepresentation;
52
56
  return dom;
53
57
  },
54
58
  };
@@ -18,7 +18,7 @@ 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.buildTitles = exports.buildElementsOrder = exports.auxiliaryObjectTypes = exports.buildJournal = exports.buildAttribution = exports.buildContributorRole = exports.buildContribution = exports.buildColor = exports.buildParagraph = exports.buildSection = exports.buildCorresp = exports.buildFootnotesOrder = exports.buildFootnote = exports.buildNote = exports.buildComment = exports.buildSupplementaryMaterial = exports.buildAffiliation = exports.buildFigure = exports.buildKeywordGroup = exports.buildKeyword = exports.buildBibliographyElement = exports.buildBibliographicDate = exports.buildBibliographicName = exports.buildBibliographyItem = exports.buildContributor = exports.buildManuscript = exports.buildProject = void 0;
21
+ exports.buildTitles = exports.buildElementsOrder = exports.auxiliaryObjectTypes = exports.buildJournal = exports.buildAttribution = exports.buildContributorRole = exports.buildContribution = exports.buildColor = exports.buildParagraph = exports.buildSection = exports.buildCorresp = exports.buildFootnotesOrder = exports.buildFootnote = exports.buildInlineMathFragment = exports.buildNote = exports.buildComment = exports.buildSupplementaryMaterial = exports.buildAffiliation = exports.buildFigure = exports.buildKeywordGroup = exports.buildKeyword = exports.buildBibliographyElement = exports.buildBibliographicDate = exports.buildBibliographicName = exports.buildBibliographyItem = exports.buildContributor = exports.buildManuscript = exports.buildProject = void 0;
22
22
  const json_schema_1 = require("@manuscripts/json-schema");
23
23
  const w3c_xmlserializer_1 = __importDefault(require("w3c-xmlserializer"));
24
24
  const schema_1 = require("../schema");
@@ -115,6 +115,13 @@ const buildNote = (target, source, contents = '') => ({
115
115
  contents,
116
116
  });
117
117
  exports.buildNote = buildNote;
118
+ const buildInlineMathFragment = (containingObject, TeXRepresentation) => ({
119
+ _id: (0, id_1.generateID)(json_schema_1.ObjectTypes.InlineMathFragment),
120
+ objectType: json_schema_1.ObjectTypes.InlineMathFragment,
121
+ containingObject: containingObject || undefined,
122
+ TeXRepresentation,
123
+ });
124
+ exports.buildInlineMathFragment = buildInlineMathFragment;
118
125
  const buildFootnote = (containingObject, contents, kind = 'footnote') => ({
119
126
  _id: (0, id_1.generateID)(json_schema_1.ObjectTypes.Footnote),
120
127
  objectType: json_schema_1.ObjectTypes.Footnote,
@@ -271,8 +271,9 @@ class Decoder {
271
271
  const model = data;
272
272
  return schema_1.schema.nodes.equation.createChecked({
273
273
  id: model._id,
274
- contents: model.contents,
275
- format: model.format,
274
+ MathMLStringRepresentation: model.MathMLStringRepresentation,
275
+ SVGStringRepresentation: model.SVGStringRepresentation,
276
+ TeXRepresentation: model.TeXRepresentation,
276
277
  });
277
278
  },
278
279
  [json_schema_1.ObjectTypes.EquationElement]: (data) => {
@@ -291,10 +292,12 @@ class Decoder {
291
292
  else {
292
293
  throw new errors_1.MissingElement(model.containedObjectID);
293
294
  }
295
+ const figcaption = this.getFigcaption(model);
294
296
  return schema_1.schema.nodes.equation_element.createChecked({
295
297
  id: model._id,
296
- label: model.label,
297
- }, [equation]);
298
+ suppressCaption: Boolean(model.suppressCaption),
299
+ suppressTitle: Boolean(model.suppressTitle === undefined ? true : model.suppressTitle),
300
+ }, [equation, figcaption]);
298
301
  },
299
302
  [json_schema_1.ObjectTypes.FootnotesElement]: (data) => {
300
303
  const foonotesElementModel = data;
@@ -62,6 +62,12 @@ const listContents = (node) => {
62
62
  }
63
63
  return (0, w3c_xmlserializer_1.default)(output);
64
64
  };
65
+ const svgDefs = (svg) => {
66
+ const template = document.createElement('template');
67
+ template.innerHTML = svg.trim();
68
+ const defs = template.content.querySelector('defs');
69
+ return defs ? (0, w3c_xmlserializer_1.default)(defs) : undefined;
70
+ };
65
71
  const tableRowDisplayStyle = (tagName, parent) => {
66
72
  switch (tagName) {
67
73
  case 'thead':
@@ -347,12 +353,20 @@ const encoders = {
347
353
  : false,
348
354
  }),
349
355
  equation: (node) => ({
350
- contents: node.attrs.contents,
351
- format: node.attrs.format,
356
+ MathMLStringRepresentation: node.attrs.MathMLStringRepresentation || undefined,
357
+ TeXRepresentation: node.attrs.TeXRepresentation,
358
+ SVGStringRepresentation: node.attrs.SVGStringRepresentation,
352
359
  }),
353
360
  equation_element: (node) => ({
354
361
  containedObjectID: attributeOfNodeType(node, 'equation', 'id'),
355
- label: node.attrs.label,
362
+ caption: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption),
363
+ title: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption_title, false),
364
+ elementType: 'p',
365
+ suppressCaption: Boolean(node.attrs.suppressCaption) || undefined,
366
+ suppressTitle: node.attrs.suppressTitle === undefined ||
367
+ node.attrs.suppressTitle === true
368
+ ? undefined
369
+ : false,
356
370
  }),
357
371
  figure: (node) => ({
358
372
  contentType: node.attrs.contentType || undefined,
@@ -399,6 +413,12 @@ const encoders = {
399
413
  .map((childNode) => childNode.attrs.id)
400
414
  .filter((id) => id),
401
415
  }),
416
+ inline_equation: (node, parent) => ({
417
+ containingObject: parent.attrs.id,
418
+ TeXRepresentation: node.attrs.TeXRepresentation,
419
+ SVGRepresentation: node.attrs.SVGRepresentation,
420
+ SVGGlyphs: svgDefs(node.attrs.SVGRepresentation),
421
+ }),
402
422
  keyword: (node, parent) => ({
403
423
  containedGroup: parent.attrs.id,
404
424
  name: keywordContents(node),
@@ -560,7 +580,8 @@ const encode = (node) => {
560
580
  if (placeholderTypes.includes(child.type)) {
561
581
  return;
562
582
  }
563
- if (parent.type === schema_1.schema.nodes.paragraph) {
583
+ if (parent.type === schema_1.schema.nodes.paragraph &&
584
+ child.type !== schema_1.schema.nodes.inline_equation) {
564
585
  return;
565
586
  }
566
587
  const { model, markers } = (0, exports.modelFromNode)(child, parent, path, priority);
@@ -39,6 +39,7 @@ exports.nodeTypesMap = new Map([
39
39
  [schema_1.schema.nodes.footnotes_section, json_schema_1.ObjectTypes.Section],
40
40
  [schema_1.schema.nodes.graphical_abstract_section, json_schema_1.ObjectTypes.Section],
41
41
  [schema_1.schema.nodes.highlight_marker, json_schema_1.ObjectTypes.HighlightMarker],
42
+ [schema_1.schema.nodes.inline_equation, json_schema_1.ObjectTypes.InlineMathFragment],
42
43
  [schema_1.schema.nodes.keyword, json_schema_1.ObjectTypes.Keyword],
43
44
  [schema_1.schema.nodes.keywords_element, json_schema_1.ObjectTypes.KeywordsElement],
44
45
  [schema_1.schema.nodes.keywords, json_schema_1.ObjectTypes.Section],
@@ -38,6 +38,7 @@ exports.manuscriptObjects = [
38
38
  json_schema_1.ObjectTypes.CommentAnnotation,
39
39
  json_schema_1.ObjectTypes.Contributor,
40
40
  json_schema_1.ObjectTypes.Footnote,
41
+ json_schema_1.ObjectTypes.InlineMathFragment,
41
42
  json_schema_1.ObjectTypes.Section,
42
43
  ].concat(exports.elementObjects);
43
44
  const isManuscriptModel = (model) => {
package/dist/es/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './lib/section-group-type';
2
2
  export * from './lib/table-cell-styles';
3
3
  export * from './lib/utils';
4
+ export * from './mathjax';
4
5
  export * from './schema';
5
6
  export * from './transformer';
6
7
  export * from './jats';
@@ -15,8 +15,10 @@
15
15
  */
16
16
  import mime from 'mime';
17
17
  import { DOMParser, Fragment } from 'prosemirror-model';
18
+ import { convertMathMLToSVG } from '../../mathjax/mathml-to-svg';
19
+ import { convertTeXToSVG } from '../../mathjax/tex-to-svg';
18
20
  import { schema } from '../../schema';
19
- import { chooseSectionCategory } from '../../transformer';
21
+ import { chooseSectionCategory, xmlSerializer } from '../../transformer';
20
22
  const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
21
23
  const chooseContentType = (graphicNode) => {
22
24
  if (graphicNode) {
@@ -31,24 +33,6 @@ const chooseContentType = (graphicNode) => {
31
33
  }
32
34
  }
33
35
  };
34
- const getEquationContent = (p) => {
35
- var _a;
36
- const element = p;
37
- const container = (_a = element.querySelector('alternatives')) !== null && _a !== void 0 ? _a : element;
38
- let contents = '';
39
- let format = '';
40
- for (const child of container.childNodes) {
41
- const nodeName = child.nodeName.replace(/^[a-z]:/, '');
42
- switch (nodeName) {
43
- case 'tex-math':
44
- case 'mml:math':
45
- contents = child.outerHTML;
46
- format = nodeName === 'tex-math' ? 'tex' : 'mathml';
47
- break;
48
- }
49
- }
50
- return { format, contents };
51
- };
52
36
  const marks = [
53
37
  {
54
38
  tag: 'bold',
@@ -157,27 +141,91 @@ const nodes = [
157
141
  tag: 'inline-formula',
158
142
  node: 'inline_equation',
159
143
  getAttrs: (node) => {
144
+ var _a, _b, _c, _d, _e;
160
145
  const element = node;
161
- return getEquationContent(element);
146
+ const attrs = {
147
+ id: element.getAttribute('id'),
148
+ MathMLRepresentation: '',
149
+ SVGRepresentation: '',
150
+ TeXRepresentation: '',
151
+ };
152
+ const container = (_a = element.querySelector('alternatives')) !== null && _a !== void 0 ? _a : element;
153
+ for (const child of container.childNodes) {
154
+ const nodeName = child.nodeName.replace(/^[a-z]:/, '');
155
+ switch (nodeName) {
156
+ case 'tex-math':
157
+ attrs.TeXRepresentation = (_c = (_b = child.textContent) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : '';
158
+ if (attrs.TeXRepresentation) {
159
+ attrs.SVGRepresentation =
160
+ (_d = convertTeXToSVG(attrs.TeXRepresentation, true)) !== null && _d !== void 0 ? _d : '';
161
+ }
162
+ break;
163
+ case 'mml:math':
164
+ ;
165
+ child.removeAttribute('id');
166
+ attrs.MathMLRepresentation = xmlSerializer.serializeToString(child);
167
+ if (attrs.MathMLRepresentation) {
168
+ attrs.SVGRepresentation =
169
+ (_e = convertMathMLToSVG(attrs.MathMLRepresentation, true)) !== null && _e !== void 0 ? _e : '';
170
+ }
171
+ break;
172
+ }
173
+ }
174
+ return attrs;
162
175
  },
163
176
  },
164
177
  {
165
178
  tag: 'disp-formula',
166
179
  node: 'equation_element',
167
180
  getAttrs: (node) => {
168
- var _a, _b;
169
181
  const element = node;
182
+ const caption = element.querySelector('figcaption');
170
183
  return {
171
184
  id: element.getAttribute('id'),
172
- label: (_b = (_a = element.querySelector('label')) === null || _a === void 0 ? void 0 : _a.textContent) !== null && _b !== void 0 ? _b : '',
185
+ suppressCaption: !caption,
173
186
  };
174
187
  },
175
188
  getContent: (node, schema) => {
189
+ var _a, _b, _c, _d, _e;
176
190
  const element = node;
177
- const attrs = getEquationContent(element);
178
- const id = element.getAttribute('id');
191
+ const attrs = {
192
+ MathMLStringRepresentation: '',
193
+ SVGStringRepresentation: '',
194
+ TeXRepresentation: '',
195
+ };
196
+ const container = (_a = element.querySelector('alternatives')) !== null && _a !== void 0 ? _a : element;
197
+ for (const child of container.childNodes) {
198
+ const nodeName = child.nodeName.replace(/^[a-z]:/, '');
199
+ switch (nodeName) {
200
+ case 'tex-math':
201
+ attrs.TeXRepresentation = (_c = (_b = child.textContent) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : '';
202
+ if (attrs.TeXRepresentation) {
203
+ attrs.SVGStringRepresentation =
204
+ (_d = convertTeXToSVG(attrs.TeXRepresentation, true)) !== null && _d !== void 0 ? _d : '';
205
+ }
206
+ break;
207
+ case 'mml:math':
208
+ ;
209
+ child.removeAttribute('id');
210
+ attrs.MathMLStringRepresentation =
211
+ xmlSerializer.serializeToString(child);
212
+ if (attrs.MathMLStringRepresentation) {
213
+ attrs.SVGStringRepresentation =
214
+ (_e = convertMathMLToSVG(attrs.MathMLStringRepresentation, true)) !== null && _e !== void 0 ? _e : '';
215
+ }
216
+ break;
217
+ }
218
+ }
219
+ const caption = element.querySelector('figcaption');
220
+ const figcaption = schema.nodes.figcaption.create();
179
221
  return Fragment.from([
180
- schema.nodes.equation.createChecked(Object.assign({ id }, attrs)),
222
+ schema.nodes.equation.createChecked(attrs),
223
+ caption
224
+ ?
225
+ jatsBodyDOMParser.parse(caption, {
226
+ topNode: figcaption,
227
+ })
228
+ : figcaption,
181
229
  ]);
182
230
  },
183
231
  },
@@ -14,13 +14,14 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { ObjectTypes, } from '@manuscripts/json-schema';
17
+ import { CitationProvider } from '@manuscripts/library';
17
18
  import debug from 'debug';
18
19
  import { DOMParser, DOMSerializer } from 'prosemirror-model';
19
20
  import serializeToXML from 'w3c-xmlserializer';
20
21
  import { nodeFromHTML, textFromHTML } from '../lib/html';
21
22
  import { normalizeStyleName } from '../lib/styled-content';
22
23
  import { iterateChildren } from '../lib/utils';
23
- import { schema, } from '../schema';
24
+ import { isCitationNode, schema, } from '../schema';
24
25
  import { generateAttachmentFilename } from '../transformer/filename';
25
26
  import { buildTargets } from '../transformer/labels';
26
27
  import { isExecutableNodeType, isNodeType } from '../transformer/node-types';
@@ -108,12 +109,22 @@ const chooseRefType = (objectType) => {
108
109
  }
109
110
  };
110
111
  const sortContributors = (a, b) => Number(a.priority) - Number(b.priority);
112
+ export const buildCitations = (citations) => citations.map((citation) => ({
113
+ citationID: citation.attrs.id,
114
+ citationItems: citation.attrs.rids.map((rid) => ({
115
+ id: rid,
116
+ })),
117
+ properties: {
118
+ noteIndex: 0,
119
+ },
120
+ }));
111
121
  export class JATSExporter {
112
122
  constructor() {
113
- this.serializeToJATS = async (fragment, modelMap, manuscriptID, options = {}) => {
114
- const { version = '1.2', doi, id, frontMatterOnly = false, links, idGenerator, mediaPathGenerator, } = options;
123
+ this.serializeToJATS = async (fragment, modelMap, manuscriptID, options) => {
124
+ const { version = '1.2', doi, id, frontMatterOnly = false, links, idGenerator, mediaPathGenerator, csl, } = options;
115
125
  this.modelMap = modelMap;
116
126
  this.models = Array.from(this.modelMap.values());
127
+ this.generateCitationTexts(fragment, csl);
117
128
  this.createSerializer();
118
129
  const versionIds = selectVersionIds(version);
119
130
  this.document = document.implementation.createDocument(null, 'article', document.implementation.createDocumentType('article', versionIds.publicId, versionIds.systemId));
@@ -145,7 +156,6 @@ export class JATSExporter {
145
156
  };
146
157
  this.nodeFromJATS = (JATSFragment) => {
147
158
  JATSFragment = JATSFragment.trim();
148
- JATSFragment = JATSFragment.replace(' ', ' ');
149
159
  if (!JATSFragment.length) {
150
160
  return null;
151
161
  }
@@ -456,10 +466,11 @@ export class JATSExporter {
456
466
  refList = this.document.createElement('ref-list');
457
467
  }
458
468
  back.appendChild(refList);
459
- const bibliographyItems = this.models.filter(hasObjectType(ObjectTypes.BibliographyItem));
460
- for (const bibliographyItem of bibliographyItems) {
469
+ const [meta] = this.citationProvider.makeBibliography();
470
+ for (const id of meta.entry_ids) {
471
+ const bibliographyItem = this.modelMap.get(id[0]);
461
472
  const ref = this.document.createElement('ref');
462
- ref.setAttribute('id', normalizeID(bibliographyItem._id));
473
+ ref.setAttribute('id', normalizeID(id[0]));
463
474
  const updateCitationPubType = (citationEl, pubType) => {
464
475
  if (pubType) {
465
476
  switch (pubType) {
@@ -632,12 +643,11 @@ export class JATSExporter {
632
643
  const xref = this.document.createElement('xref');
633
644
  xref.setAttribute('ref-type', 'bibr');
634
645
  xref.setAttribute('rid', normalizeID(rids.join(' ')));
635
- if (citation.attrs.contents) {
636
- const text = textFromHTML(node.attrs.contents);
637
- if (text !== null && text.length) {
638
- xref.textContent = text;
639
- }
646
+ const citationTextContent = this.citationTexts.get(node.attrs.id);
647
+ if (!citationTextContent) {
648
+ throw new Error(`No citation text found for ${node.attrs.id}`);
640
649
  }
650
+ xref.textContent = textFromHTML(citationTextContent);
641
651
  return xref;
642
652
  },
643
653
  cross_reference: (node) => {
@@ -666,23 +676,22 @@ export class JATSExporter {
666
676
  },
667
677
  doc: () => '',
668
678
  equation: (node) => {
669
- const math = this.nodeFromJATS(node.attrs.contents);
670
- const mathEl = math;
671
- mathEl.setAttribute('id', normalizeID(node.attrs.id));
672
- return mathEl;
673
- },
674
- inline_equation: (node) => {
675
- const eqElement = this.document.createElement('inline-formula');
676
- const math = this.nodeFromJATS(node.attrs.contents);
677
- eqElement.append(math);
678
- return eqElement;
679
- },
680
- equation_element: (node) => {
681
- const eqElement = this.document.createElement('disp-formula');
682
- eqElement.setAttribute('id', normalizeID(node.attrs.id));
683
- processChildNodes(eqElement, node, schema.nodes.equation);
684
- return eqElement;
679
+ const formula = this.document.createElement('disp-formula');
680
+ formula.setAttribute('id', normalizeID(node.attrs.id));
681
+ if (node.attrs.TeXRepresentation) {
682
+ const math = this.document.createElement('tex-math');
683
+ math.textContent = node.attrs.TeXRepresentation;
684
+ formula.appendChild(math);
685
+ }
686
+ else if (node.attrs.MathMLStringRepresentation) {
687
+ const math = this.nodeFromJATS(node.attrs.MathMLStringRepresentation);
688
+ if (math) {
689
+ formula.appendChild(math);
690
+ }
691
+ }
692
+ return formula;
685
693
  },
694
+ equation_element: (node) => createFigureElement(node, 'fig', node.type.schema.nodes.equation, 'equation'),
686
695
  figcaption: (node) => {
687
696
  if (!node.textContent) {
688
697
  return '';
@@ -732,6 +741,28 @@ export class JATSExporter {
732
741
  },
733
742
  hard_break: () => '',
734
743
  highlight_marker: () => '',
744
+ inline_equation: (node) => {
745
+ const formula = this.document.createElement('inline-formula');
746
+ formula.setAttribute('id', normalizeID(node.attrs.id));
747
+ if (node.attrs.TeXRepresentation) {
748
+ const math = this.document.createElement('tex-math');
749
+ math.textContent = node.attrs.TeXRepresentation;
750
+ formula.appendChild(math);
751
+ }
752
+ else if (node.attrs.MathMLRepresentation) {
753
+ const math = this.nodeFromJATS(node.attrs.MathMLRepresentation);
754
+ if (math) {
755
+ formula.appendChild(math);
756
+ }
757
+ }
758
+ else if (node.attrs.SVGRepresentation) {
759
+ const math = this.nodeFromJATS(node.attrs.SVGRepresentation);
760
+ if (math) {
761
+ formula.appendChild(math);
762
+ }
763
+ }
764
+ return formula;
765
+ },
735
766
  inline_footnote: (node) => {
736
767
  const xref = this.document.createElement('xref');
737
768
  xref.setAttribute('ref-type', 'fn');
@@ -1527,6 +1558,27 @@ export class JATSExporter {
1527
1558
  return name;
1528
1559
  };
1529
1560
  }
1561
+ generateCitations(fragment) {
1562
+ const nodes = [];
1563
+ fragment.descendants((node) => {
1564
+ if (isCitationNode(node)) {
1565
+ nodes.push(node);
1566
+ }
1567
+ });
1568
+ return buildCitations(nodes);
1569
+ }
1570
+ generateCitationTexts(fragment, csl) {
1571
+ this.citationTexts = new Map();
1572
+ this.citationProvider = new CitationProvider({
1573
+ getLibraryItem: (id) => this.modelMap.get(id),
1574
+ locale: csl.locale,
1575
+ citationStyle: csl.style,
1576
+ });
1577
+ const citations = this.generateCitations(fragment);
1578
+ this.citationProvider.rebuildState(citations).forEach(([id, , output]) => {
1579
+ this.citationTexts.set(id, output);
1580
+ });
1581
+ }
1530
1582
  buildKeywords(articleMeta) {
1531
1583
  const keywords = [...this.modelMap.values()].filter((model) => model.objectType === ObjectTypes.Keyword);
1532
1584
  const keywordGroups = new Map();
@@ -0,0 +1,12 @@
1
+ export const convertMathMLToSVG = async (mathml, display) => {
2
+ const { convertMathMLToSVG } = await import('./mathml-to-svg');
3
+ return convertMathMLToSVG(mathml, display);
4
+ };
5
+ export const convertTeXToMathML = async (tex, display) => {
6
+ const { convertTeXToMathML } = await import('./tex-to-mathml');
7
+ return convertTeXToMathML(tex, display);
8
+ };
9
+ export const convertTeXToSVG = async (tex, display) => {
10
+ const { convertTeXToSVG } = await import('./tex-to-svg');
11
+ return convertTeXToSVG(tex, display);
12
+ };
@@ -0,0 +1,17 @@
1
+ /*!
2
+ * © 2019 Atypon Systems LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { AllPackages } from 'mathjax-full/js/input/tex/AllPackages';
17
+ export const packages = AllPackages.filter((name) => name !== 'html' && name !== 'bussproofs');
@@ -0,0 +1,66 @@
1
+ /*!
2
+ * © 2019 Atypon Systems LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import 'mathjax-full/js/util/entities/all';
17
+ import { HTMLAdaptor } from 'mathjax-full/js/adaptors/HTMLAdaptor';
18
+ import { MmlFactory } from 'mathjax-full/js/core/MmlTree/MmlFactory';
19
+ import { HTMLDocument } from 'mathjax-full/js/handlers/html/HTMLDocument';
20
+ import { MathML } from 'mathjax-full/js/input/mathml';
21
+ import { SVG } from 'mathjax-full/js/output/svg';
22
+ import { xmlSerializer } from '../transformer';
23
+ class ManuscriptsMmlFactory extends MmlFactory {
24
+ constructor() {
25
+ super();
26
+ this.nodeMap.set('image', this.nodeMap.get('none'));
27
+ }
28
+ create(kind, properties = {}, children = []) {
29
+ if (kind === 'image') {
30
+ return this.node['none'](properties, children);
31
+ }
32
+ return this.node[kind](properties, children);
33
+ }
34
+ }
35
+ class ManuscriptsHTMLAdaptor extends HTMLAdaptor {
36
+ setAttribute(node, name, value, ns) {
37
+ if (name !== 'xmlns') {
38
+ ns ? node.setAttributeNS(ns, name, value) : node.setAttribute(name, value);
39
+ }
40
+ }
41
+ }
42
+ const InputJax = new MathML();
43
+ const OutputJax = new SVG({
44
+ fontCache: 'none',
45
+ });
46
+ const adaptor = new ManuscriptsHTMLAdaptor(window);
47
+ const doc = new HTMLDocument(document, adaptor, {
48
+ InputJax,
49
+ OutputJax,
50
+ MmlFactory: new ManuscriptsMmlFactory(),
51
+ });
52
+ doc.addStyleSheet();
53
+ export const convertMathMLToSVG = (mathml, display) => {
54
+ const item = doc.convert(mathml, {
55
+ display,
56
+ em: 16,
57
+ ex: 8,
58
+ containerWidth: 1000000,
59
+ lineWidth: 1000000,
60
+ scale: 1,
61
+ });
62
+ if (!item || !item.firstChild) {
63
+ return null;
64
+ }
65
+ return xmlSerializer.serializeToString(item.firstChild);
66
+ };
@@ -0,0 +1,45 @@
1
+ /*!
2
+ * © 2019 Atypon Systems LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import 'mathjax-full/js/util/entities/all';
17
+ import { HTMLAdaptor } from 'mathjax-full/js/adaptors/HTMLAdaptor';
18
+ import { STATE } from 'mathjax-full/js/core/MathItem.js';
19
+ import { SerializedMmlVisitor } from 'mathjax-full/js/core/MmlTree/SerializedMmlVisitor';
20
+ import { HTMLDocument } from 'mathjax-full/js/handlers/html/HTMLDocument';
21
+ import { TeX } from 'mathjax-full/js/input/tex';
22
+ import { packages } from './mathjax-packages';
23
+ const InputJax = new TeX({
24
+ packages,
25
+ });
26
+ const adaptor = new HTMLAdaptor(window);
27
+ const doc = new HTMLDocument(document, adaptor, {
28
+ InputJax,
29
+ });
30
+ const visitor = new SerializedMmlVisitor();
31
+ export const convertTeXToMathML = (tex, display) => {
32
+ const item = doc.convert(tex, {
33
+ display,
34
+ em: 16,
35
+ ex: 8,
36
+ containerWidth: 1000000,
37
+ lineWidth: 1000000,
38
+ scale: 1,
39
+ end: STATE.CONVERT,
40
+ });
41
+ if (!item) {
42
+ return null;
43
+ }
44
+ return visitor.visitTree(item);
45
+ };