@manuscripts/transform 1.3.5-LIT-528106 → 1.3.6
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/cjs/lib/utils.js +1 -14
- package/dist/cjs/mathjax/mathml-to-svg.js +14 -0
- package/dist/cjs/transformer/encode.js +3 -10
- package/dist/es/lib/utils.js +0 -12
- package/dist/es/mathjax/mathml-to-svg.js +14 -0
- package/dist/es/transformer/encode.js +4 -11
- package/dist/types/lib/utils.d.ts +0 -2
- package/dist/types/transformer/encode.d.ts +1 -1
- package/package.json +1 -1
package/dist/cjs/lib/utils.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.
|
|
18
|
+
exports.getTrimmedTextContent = exports.findParentNodeClosestToPos = exports.isInBibliographySection = exports.isInGraphicalAbstractSection = exports.findNodePositions = exports.iterateChildren = void 0;
|
|
19
19
|
const bibliography_section_1 = require("../schema/nodes/bibliography_section");
|
|
20
20
|
const graphical_abstract_section_1 = require("../schema/nodes/graphical_abstract_section");
|
|
21
21
|
function* iterateChildren(node, recurse = false) {
|
|
@@ -83,16 +83,3 @@ const getTrimmedTextContent = (node, querySelector) => {
|
|
|
83
83
|
return (_b = (_a = node.querySelector(querySelector)) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.trim();
|
|
84
84
|
};
|
|
85
85
|
exports.getTrimmedTextContent = getTrimmedTextContent;
|
|
86
|
-
function modelsEqual(model, model2) {
|
|
87
|
-
for (const v in model) {
|
|
88
|
-
for (const v2 in model2) {
|
|
89
|
-
const prepV = typeof v == 'object' ? JSON.stringify(v) : v;
|
|
90
|
-
const prepV2 = typeof v2 == 'object' ? JSON.stringify(v2) : v2;
|
|
91
|
-
if (prepV !== prepV2) {
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
exports.modelsEqual = modelsEqual;
|
|
@@ -18,10 +18,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
18
18
|
exports.convertMathMLToSVG = void 0;
|
|
19
19
|
require("mathjax-full/js/util/entities/all");
|
|
20
20
|
const HTMLAdaptor_1 = require("mathjax-full/js/adaptors/HTMLAdaptor");
|
|
21
|
+
const MmlFactory_1 = require("mathjax-full/js/core/MmlTree/MmlFactory");
|
|
21
22
|
const HTMLDocument_1 = require("mathjax-full/js/handlers/html/HTMLDocument");
|
|
22
23
|
const mathml_1 = require("mathjax-full/js/input/mathml");
|
|
23
24
|
const svg_1 = require("mathjax-full/js/output/svg");
|
|
24
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
|
+
}
|
|
25
38
|
class ManuscriptsHTMLAdaptor extends HTMLAdaptor_1.HTMLAdaptor {
|
|
26
39
|
setAttribute(node, name, value, ns) {
|
|
27
40
|
if (name !== 'xmlns') {
|
|
@@ -37,6 +50,7 @@ const adaptor = new ManuscriptsHTMLAdaptor(window);
|
|
|
37
50
|
const doc = new HTMLDocument_1.HTMLDocument(document, adaptor, {
|
|
38
51
|
InputJax,
|
|
39
52
|
OutputJax,
|
|
53
|
+
MmlFactory: new ManuscriptsMmlFactory(),
|
|
40
54
|
});
|
|
41
55
|
doc.addStyleSheet();
|
|
42
56
|
const convertMathMLToSVG = (mathml, display) => {
|
|
@@ -25,7 +25,6 @@ const utils_1 = require("../lib/utils");
|
|
|
25
25
|
const schema_1 = require("../schema");
|
|
26
26
|
const builders_1 = require("./builders");
|
|
27
27
|
const highlight_markers_1 = require("./highlight-markers");
|
|
28
|
-
const id_1 = require("./id");
|
|
29
28
|
const node_types_1 = require("./node-types");
|
|
30
29
|
const section_category_1 = require("./section-category");
|
|
31
30
|
const serializer = prosemirror_model_1.DOMSerializer.fromSchema(schema_1.schema);
|
|
@@ -527,7 +526,7 @@ const modelFromNode = (node, parent, path, priority) => {
|
|
|
527
526
|
return { model, commentAnnotationsMap };
|
|
528
527
|
};
|
|
529
528
|
exports.modelFromNode = modelFromNode;
|
|
530
|
-
const encode = (node
|
|
529
|
+
const encode = (node) => {
|
|
531
530
|
const models = new Map();
|
|
532
531
|
const priority = {
|
|
533
532
|
value: 1,
|
|
@@ -547,14 +546,8 @@ const encode = (node, preserveWithRepeatedID = false) => {
|
|
|
547
546
|
return;
|
|
548
547
|
}
|
|
549
548
|
const { model } = (0, exports.modelFromNode)(child, parent, path, priority);
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
if (preserveWithRepeatedID && !(0, utils_1.modelsEqual)(model, existingModel)) {
|
|
553
|
-
model._id = (0, id_1.generateID)(model.objectType);
|
|
554
|
-
}
|
|
555
|
-
else {
|
|
556
|
-
throw Error(`Encountered duplicate ids in models map while encoding: ${model._id}`);
|
|
557
|
-
}
|
|
549
|
+
if (models.has(model._id)) {
|
|
550
|
+
throw Error(`Encountered duplicate ids in models map while encoding: ${model._id}`);
|
|
558
551
|
}
|
|
559
552
|
models.set(model._id, model);
|
|
560
553
|
child.forEach(addModel(path.concat(child.attrs.id), child));
|
package/dist/es/lib/utils.js
CHANGED
|
@@ -74,15 +74,3 @@ export const getTrimmedTextContent = (node, querySelector) => {
|
|
|
74
74
|
}
|
|
75
75
|
return (_b = (_a = node.querySelector(querySelector)) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.trim();
|
|
76
76
|
};
|
|
77
|
-
export function modelsEqual(model, model2) {
|
|
78
|
-
for (const v in model) {
|
|
79
|
-
for (const v2 in model2) {
|
|
80
|
-
const prepV = typeof v == 'object' ? JSON.stringify(v) : v;
|
|
81
|
-
const prepV2 = typeof v2 == 'object' ? JSON.stringify(v2) : v2;
|
|
82
|
-
if (prepV !== prepV2) {
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
@@ -15,10 +15,23 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import 'mathjax-full/js/util/entities/all';
|
|
17
17
|
import { HTMLAdaptor } from 'mathjax-full/js/adaptors/HTMLAdaptor';
|
|
18
|
+
import { MmlFactory } from 'mathjax-full/js/core/MmlTree/MmlFactory';
|
|
18
19
|
import { HTMLDocument } from 'mathjax-full/js/handlers/html/HTMLDocument';
|
|
19
20
|
import { MathML } from 'mathjax-full/js/input/mathml';
|
|
20
21
|
import { SVG } from 'mathjax-full/js/output/svg';
|
|
21
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
|
+
}
|
|
22
35
|
class ManuscriptsHTMLAdaptor extends HTMLAdaptor {
|
|
23
36
|
setAttribute(node, name, value, ns) {
|
|
24
37
|
if (name !== 'xmlns') {
|
|
@@ -34,6 +47,7 @@ const adaptor = new ManuscriptsHTMLAdaptor(window);
|
|
|
34
47
|
const doc = new HTMLDocument(document, adaptor, {
|
|
35
48
|
InputJax,
|
|
36
49
|
OutputJax,
|
|
50
|
+
MmlFactory: new ManuscriptsMmlFactory(),
|
|
37
51
|
});
|
|
38
52
|
doc.addStyleSheet();
|
|
39
53
|
export const convertMathMLToSVG = (mathml, display) => {
|
|
@@ -15,11 +15,10 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { DOMSerializer } from 'prosemirror-model';
|
|
17
17
|
import serializeToXML from 'w3c-xmlserializer';
|
|
18
|
-
import { iterateChildren
|
|
18
|
+
import { iterateChildren } from '../lib/utils';
|
|
19
19
|
import { hasGroup, isHighlightMarkerNode, isSectionNode, schema, } from '../schema';
|
|
20
20
|
import { buildAttribution } from './builders';
|
|
21
21
|
import { extractHighlightMarkers, isHighlightableModel, } from './highlight-markers';
|
|
22
|
-
import { generateID } from './id';
|
|
23
22
|
import { nodeTypesMap } from './node-types';
|
|
24
23
|
import { buildSectionCategory } from './section-category';
|
|
25
24
|
const serializer = DOMSerializer.fromSchema(schema);
|
|
@@ -518,7 +517,7 @@ export const modelFromNode = (node, parent, path, priority) => {
|
|
|
518
517
|
}
|
|
519
518
|
return { model, commentAnnotationsMap };
|
|
520
519
|
};
|
|
521
|
-
export const encode = (node
|
|
520
|
+
export const encode = (node) => {
|
|
522
521
|
const models = new Map();
|
|
523
522
|
const priority = {
|
|
524
523
|
value: 1,
|
|
@@ -538,14 +537,8 @@ export const encode = (node, preserveWithRepeatedID = false) => {
|
|
|
538
537
|
return;
|
|
539
538
|
}
|
|
540
539
|
const { model } = modelFromNode(child, parent, path, priority);
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
if (preserveWithRepeatedID && !modelsEqual(model, existingModel)) {
|
|
544
|
-
model._id = generateID(model.objectType);
|
|
545
|
-
}
|
|
546
|
-
else {
|
|
547
|
-
throw Error(`Encountered duplicate ids in models map while encoding: ${model._id}`);
|
|
548
|
-
}
|
|
540
|
+
if (models.has(model._id)) {
|
|
541
|
+
throw Error(`Encountered duplicate ids in models map while encoding: ${model._id}`);
|
|
549
542
|
}
|
|
550
543
|
models.set(model._id, model);
|
|
551
544
|
child.forEach(addModel(path.concat(child.attrs.id), child));
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { Model } from '@manuscripts/json-schema';
|
|
17
16
|
import { Node as ProsemirrorNode, ResolvedPos } from 'prosemirror-model';
|
|
18
17
|
import { ManuscriptEditorState, ManuscriptNode } from '../schema';
|
|
19
18
|
export declare function iterateChildren(node: ManuscriptNode, recurse?: boolean): Iterable<ManuscriptNode>;
|
|
@@ -27,4 +26,3 @@ export declare const findParentNodeClosestToPos: ($pos: ResolvedPos, predicate:
|
|
|
27
26
|
node: ProsemirrorNode;
|
|
28
27
|
} | undefined;
|
|
29
28
|
export declare const getTrimmedTextContent: (node: Element | Document, querySelector: string) => string | null | undefined;
|
|
30
|
-
export declare function modelsEqual(model: Model, model2: Model): boolean;
|
|
@@ -25,5 +25,5 @@ export declare const modelFromNode: (node: ManuscriptNode, parent: ManuscriptNod
|
|
|
25
25
|
interface PrioritizedValue {
|
|
26
26
|
value: number;
|
|
27
27
|
}
|
|
28
|
-
export declare const encode: (node: ManuscriptNode
|
|
28
|
+
export declare const encode: (node: ManuscriptNode) => Map<string, Model>;
|
|
29
29
|
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manuscripts/transform",
|
|
3
3
|
"description": "ProseMirror transformer for Manuscripts applications",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.6",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-transform",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|