@manuscripts/transform 4.3.53 → 4.4.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.
- package/dist/cjs/jats/__tests__/jats-roundtrip.test.js +3 -3
- package/dist/cjs/version.js +1 -1
- package/dist/es/jats/__tests__/jats-roundtrip.test.js +3 -3
- package/dist/es/version.js +1 -1
- package/dist/types/jats/__tests__/utils.d.ts +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +22 -21
- package/src/errors.ts +28 -0
- package/src/getVersion.ts +21 -0
- package/src/index.ts +28 -0
- package/src/jats/__tests__/__fixtures__/debug-example.xml +136 -0
- package/src/jats/__tests__/__fixtures__/jats-abstract-no-body.xml +163 -0
- package/src/jats/__tests__/__fixtures__/jats-citations.xml +472 -0
- package/src/jats/__tests__/__fixtures__/jats-comments.xml +46 -0
- package/src/jats/__tests__/__fixtures__/jats-document.xml +134 -0
- package/src/jats/__tests__/__fixtures__/jats-example-doc.xml +1235 -0
- package/src/jats/__tests__/__fixtures__/jats-example-front-only.xml +26 -0
- package/src/jats/__tests__/__fixtures__/jats-example-full.xml +209 -0
- package/src/jats/__tests__/__fixtures__/jats-example-no-back.xml +156 -0
- package/src/jats/__tests__/__fixtures__/jats-example-no-body.xml +91 -0
- package/src/jats/__tests__/__fixtures__/jats-example.xml +221 -0
- package/src/jats/__tests__/__fixtures__/jats-fn-group.xml +60 -0
- package/src/jats/__tests__/__fixtures__/jats-import-no-refs.xml +1077 -0
- package/src/jats/__tests__/__fixtures__/jats-import.xml +1561 -0
- package/src/jats/__tests__/__fixtures__/jats-roundtrip.xml +133 -0
- package/src/jats/__tests__/__fixtures__/jats-tables-example.xml +2043 -0
- package/src/jats/__tests__/__fixtures__/math-fragment.xml +12 -0
- package/src/jats/__tests__/__snapshots__/citeproc.test.ts.snap +57 -0
- package/src/jats/__tests__/__snapshots__/create-article-node.test.ts.snap +65 -0
- package/src/jats/__tests__/__snapshots__/jats-exporter.test.ts.snap +7 -0
- package/src/jats/__tests__/__snapshots__/jats-importer.test.ts.snap +59605 -0
- package/src/jats/__tests__/__snapshots__/jats-roundtrip.test.ts.snap +18 -0
- package/src/jats/__tests__/citations.ts +25 -0
- package/src/jats/__tests__/citeproc.test.ts +195 -0
- package/src/jats/__tests__/create-article-node.test.ts +29 -0
- package/src/jats/__tests__/data/section-categories.ts +212 -0
- package/src/jats/__tests__/files.ts +24 -0
- package/src/jats/__tests__/jats-exporter.test.ts +223 -0
- package/src/jats/__tests__/jats-importer.test.ts +567 -0
- package/src/jats/__tests__/jats-roundtrip.test.ts +66 -0
- package/src/jats/__tests__/utils.ts +90 -0
- package/src/jats/exporter/citeproc.ts +265 -0
- package/src/jats/exporter/jats-exporter.ts +2090 -0
- package/src/jats/exporter/jats-versions.ts +50 -0
- package/src/jats/exporter/labels.ts +101 -0
- package/src/jats/importer/create-article-node.ts +52 -0
- package/src/jats/importer/jats-comments.ts +111 -0
- package/src/jats/importer/jats-dom-parser.ts +1260 -0
- package/src/jats/importer/jats-parser-utils.ts +234 -0
- package/src/jats/importer/jats-transformations.ts +591 -0
- package/src/jats/importer/parse-jats-article.ts +106 -0
- package/src/jats/index.ts +21 -0
- package/src/jats/types.ts +16 -0
- package/src/lib/__tests__/footnotes.test.ts +36 -0
- package/src/lib/citeproc.ts +30 -0
- package/src/lib/credit-roles.ts +91 -0
- package/src/lib/deafults.ts +17 -0
- package/src/lib/footnotes.ts +85 -0
- package/src/lib/html.ts +56 -0
- package/src/lib/section-categories.ts +27 -0
- package/src/lib/utils.ts +145 -0
- package/src/lib/xml.ts +28 -0
- package/src/schema/__tests__/docs.ts +1911 -0
- package/src/schema/__tests__/groups.test.ts +61 -0
- package/src/schema/__tests__/migration.test.ts +23 -0
- package/src/schema/groups.ts +36 -0
- package/src/schema/index.ts +286 -0
- package/src/schema/marks.ts +254 -0
- package/src/schema/migration/migrate.ts +77 -0
- package/src/schema/migration/migration-script.ts +26 -0
- package/src/schema/migration/migration-scripts/1.2.5.ts +44 -0
- package/src/schema/migration/migration-scripts/2.3.22.ts +52 -0
- package/src/schema/migration/migration-scripts/3.0.12.ts +33 -0
- package/src/schema/migration/migration-scripts/3.0.21.ts +50 -0
- package/src/schema/migration/migration-scripts/3.0.30.ts +65 -0
- package/src/schema/migration/migration-scripts/3.0.31.ts +40 -0
- package/src/schema/migration/migration-scripts/3.0.41.ts +37 -0
- package/src/schema/migration/migration-scripts/3.0.55.ts +42 -0
- package/src/schema/migration/migration-scripts/3.0.56.ts +114 -0
- package/src/schema/migration/migration-scripts/4.2.13.ts +37 -0
- package/src/schema/migration/migration-scripts/4.2.15.ts +48 -0
- package/src/schema/migration/migration-scripts/4.3.23.ts +55 -0
- package/src/schema/migration/migration-scripts/4.3.34.ts +132 -0
- package/src/schema/migration/migration-scripts/4.3.35.ts +41 -0
- package/src/schema/migration/migration-scripts/index.ts +49 -0
- package/src/schema/nodes/abstracts.ts +29 -0
- package/src/schema/nodes/affiliation.ts +88 -0
- package/src/schema/nodes/affiliations.ts +30 -0
- package/src/schema/nodes/alt_text.ts +36 -0
- package/src/schema/nodes/alt_title.ts +40 -0
- package/src/schema/nodes/alt_titles_section.ts +58 -0
- package/src/schema/nodes/attachment.ts +46 -0
- package/src/schema/nodes/attachments.ts +45 -0
- package/src/schema/nodes/attribution.ts +38 -0
- package/src/schema/nodes/author_notes.ts +44 -0
- package/src/schema/nodes/award.ts +52 -0
- package/src/schema/nodes/awards.ts +45 -0
- package/src/schema/nodes/backmatter.ts +31 -0
- package/src/schema/nodes/bibliography_element.ts +58 -0
- package/src/schema/nodes/bibliography_item.ts +108 -0
- package/src/schema/nodes/bibliography_section.ts +60 -0
- package/src/schema/nodes/blockquote_element.ts +79 -0
- package/src/schema/nodes/body.ts +29 -0
- package/src/schema/nodes/box_element.ts +67 -0
- package/src/schema/nodes/caption.ts +67 -0
- package/src/schema/nodes/caption_title.ts +67 -0
- package/src/schema/nodes/citation.ts +70 -0
- package/src/schema/nodes/comment.ts +50 -0
- package/src/schema/nodes/comments.ts +28 -0
- package/src/schema/nodes/contributor.ts +87 -0
- package/src/schema/nodes/contributors.ts +40 -0
- package/src/schema/nodes/core_section.ts +27 -0
- package/src/schema/nodes/corresp.ts +49 -0
- package/src/schema/nodes/cross_reference.ts +64 -0
- package/src/schema/nodes/doc.ts +21 -0
- package/src/schema/nodes/embed.ts +55 -0
- package/src/schema/nodes/equation.ts +65 -0
- package/src/schema/nodes/equation_element.ts +61 -0
- package/src/schema/nodes/figure.ts +65 -0
- package/src/schema/nodes/figure_element.ts +73 -0
- package/src/schema/nodes/footnote.ts +95 -0
- package/src/schema/nodes/footnotes_element.ts +69 -0
- package/src/schema/nodes/footnotes_section.ts +61 -0
- package/src/schema/nodes/general_table_footnote.ts +42 -0
- package/src/schema/nodes/graphical_abstract_section.ts +62 -0
- package/src/schema/nodes/hard_break.ts +36 -0
- package/src/schema/nodes/hero_image.ts +46 -0
- package/src/schema/nodes/highlight_marker.ts +68 -0
- package/src/schema/nodes/image_element.ts +49 -0
- package/src/schema/nodes/inline_equation.ts +68 -0
- package/src/schema/nodes/inline_footnote.ts +66 -0
- package/src/schema/nodes/keyword.ts +61 -0
- package/src/schema/nodes/keyword_group.ts +63 -0
- package/src/schema/nodes/keywords.ts +59 -0
- package/src/schema/nodes/keywords_element.ts +64 -0
- package/src/schema/nodes/link.ts +79 -0
- package/src/schema/nodes/list.ts +134 -0
- package/src/schema/nodes/listing.ts +91 -0
- package/src/schema/nodes/listing_element.ts +61 -0
- package/src/schema/nodes/long_desc.ts +36 -0
- package/src/schema/nodes/manuscript.ts +86 -0
- package/src/schema/nodes/missing_figure.ts +59 -0
- package/src/schema/nodes/paragraph.ts +77 -0
- package/src/schema/nodes/placeholder.ts +62 -0
- package/src/schema/nodes/placeholder_element.ts +60 -0
- package/src/schema/nodes/pullquote_element.ts +81 -0
- package/src/schema/nodes/quote_image.ts +64 -0
- package/src/schema/nodes/section.ts +69 -0
- package/src/schema/nodes/section_label.ts +39 -0
- package/src/schema/nodes/section_title.ts +58 -0
- package/src/schema/nodes/subtitle.ts +40 -0
- package/src/schema/nodes/subtitles.ts +51 -0
- package/src/schema/nodes/supplement.ts +77 -0
- package/src/schema/nodes/supplements.ts +60 -0
- package/src/schema/nodes/table.ts +144 -0
- package/src/schema/nodes/table_col.ts +76 -0
- package/src/schema/nodes/table_element.ts +67 -0
- package/src/schema/nodes/table_element_footer.ts +42 -0
- package/src/schema/nodes/text.ts +31 -0
- package/src/schema/nodes/title.ts +43 -0
- package/src/schema/nodes/trans_abstract.ts +58 -0
- package/src/schema/nodes/trans_graphical_abstract.ts +67 -0
- package/src/schema/types.ts +240 -0
- package/src/tests.ts +33 -0
- package/src/transformer/id.ts +23 -0
- package/src/transformer/index.ts +21 -0
- package/src/transformer/node-names.ts +73 -0
- package/src/transformer/node-title.ts +111 -0
- package/src/transformer/node-types.ts +39 -0
- package/src/transformer/node-validator.ts +82 -0
- package/src/types.ts +25 -0
- package/src/version.ts +1 -0
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
|
|
17
|
+
interface VersionIds {
|
|
18
|
+
publicId: string
|
|
19
|
+
systemId: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type Version = '1.1' | '1.2d1' | '1.2'
|
|
23
|
+
|
|
24
|
+
const versions: { [key in Version]: VersionIds } = {
|
|
25
|
+
'1.1': {
|
|
26
|
+
publicId:
|
|
27
|
+
'-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD with OASIS Tables with MathML3 v1.1 20151215//EN',
|
|
28
|
+
systemId:
|
|
29
|
+
'http://jats.nlm.nih.gov/archiving/1.1/JATS-archive-oasis-article1-mathml3.dtd',
|
|
30
|
+
},
|
|
31
|
+
'1.2d1': {
|
|
32
|
+
publicId:
|
|
33
|
+
'-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD with OASIS Tables with MathML3 v1.2d1 20170631//EN',
|
|
34
|
+
systemId:
|
|
35
|
+
'http://jats.nlm.nih.gov/archiving/1.2d1/JATS-archive-oasis-article1-mathml3.dtd',
|
|
36
|
+
},
|
|
37
|
+
'1.2': {
|
|
38
|
+
publicId:
|
|
39
|
+
'-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD with OASIS Tables with MathML3 v1.2 20190208//EN',
|
|
40
|
+
systemId:
|
|
41
|
+
'http://jats.nlm.nih.gov/archiving/1.2/JATS-archive-oasis-article1-mathml3.dtd',
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const selectVersionIds = (version: Version): VersionIds => {
|
|
46
|
+
if (!(version in versions)) {
|
|
47
|
+
throw new Error(`Unknown version ${version}`)
|
|
48
|
+
}
|
|
49
|
+
return versions[version]
|
|
50
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* © 2020 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
|
+
|
|
17
|
+
import { ManuscriptNode, ManuscriptNodeType, schema } from '../../schema'
|
|
18
|
+
import { nodeNames } from '../../transformer/node-names'
|
|
19
|
+
|
|
20
|
+
export interface Target {
|
|
21
|
+
type: string
|
|
22
|
+
id: string
|
|
23
|
+
label: string
|
|
24
|
+
caption: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface Counter {
|
|
28
|
+
label: string
|
|
29
|
+
index: number
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface Counters {
|
|
33
|
+
[key: string]: Counter
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const labelledNodeTypes: ManuscriptNodeType[] = [
|
|
37
|
+
schema.nodes.figure_element,
|
|
38
|
+
schema.nodes.table_element,
|
|
39
|
+
schema.nodes.equation_element,
|
|
40
|
+
schema.nodes.listing_element,
|
|
41
|
+
schema.nodes.box_element,
|
|
42
|
+
schema.nodes.embed,
|
|
43
|
+
schema.nodes.image_element,
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
const excludedTypes = [schema.nodes.graphical_abstract_section]
|
|
47
|
+
|
|
48
|
+
const chooseLabel = (nodeType: ManuscriptNodeType): string => {
|
|
49
|
+
return nodeNames.get(nodeType) as string
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
type iterator = (
|
|
53
|
+
node: ManuscriptNode,
|
|
54
|
+
pos: number,
|
|
55
|
+
parent: ManuscriptNode | null,
|
|
56
|
+
index: number
|
|
57
|
+
) => void | boolean
|
|
58
|
+
|
|
59
|
+
export const buildTargets = (
|
|
60
|
+
iterator: (fn: iterator) => void
|
|
61
|
+
): Map<string, Target> => {
|
|
62
|
+
const counters: Counters = {}
|
|
63
|
+
|
|
64
|
+
for (const nodeType of labelledNodeTypes) {
|
|
65
|
+
counters[nodeType.name] = {
|
|
66
|
+
label: chooseLabel(nodeType), // choosing label name: "Figure", "Table", etc.
|
|
67
|
+
index: 0, // TODO: use manuscript.figureElementNumberingScheme
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const buildLabel = (type: ManuscriptNodeType) => {
|
|
72
|
+
const counter = counters[type.name]
|
|
73
|
+
counter.index++
|
|
74
|
+
return `${counter.label} ${counter.index}`
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const targets: Map<string, Target> = new Map()
|
|
78
|
+
|
|
79
|
+
iterator((node, pos, parent) => {
|
|
80
|
+
if (node.type.name in counters) {
|
|
81
|
+
if (parent && excludedTypes.includes(parent.type)) {
|
|
82
|
+
return
|
|
83
|
+
}
|
|
84
|
+
if (node.type === schema.nodes.box_element) {
|
|
85
|
+
const child = node.firstChild
|
|
86
|
+
if (!child || child.type !== schema.nodes.caption_title) {
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const label = buildLabel(node.type)
|
|
91
|
+
|
|
92
|
+
targets.set(node.attrs.id, {
|
|
93
|
+
type: node.type.name,
|
|
94
|
+
id: node.attrs.id,
|
|
95
|
+
label,
|
|
96
|
+
caption: node.textContent?.trim(), // TODO: HTML?
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
})
|
|
100
|
+
return targets
|
|
101
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* © 2024 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
|
+
|
|
17
|
+
import { ManuscriptAttrs, ManuscriptNode, schema } from '../../schema'
|
|
18
|
+
import { generateNodeID } from '../../transformer'
|
|
19
|
+
|
|
20
|
+
export const createArticleNode = (
|
|
21
|
+
attrs: Partial<ManuscriptAttrs> & { id: string }
|
|
22
|
+
): ManuscriptNode => {
|
|
23
|
+
const title = schema.nodes.title.createChecked({
|
|
24
|
+
id: generateNodeID(schema.nodes.title),
|
|
25
|
+
})
|
|
26
|
+
const abstracts = schema.nodes.abstracts.createChecked({
|
|
27
|
+
id: generateNodeID(schema.nodes.abstracts),
|
|
28
|
+
})
|
|
29
|
+
const paragraph = schema.nodes.paragraph.createChecked({
|
|
30
|
+
id: generateNodeID(schema.nodes.paragraph),
|
|
31
|
+
})
|
|
32
|
+
const body = schema.nodes.body.createChecked(
|
|
33
|
+
{
|
|
34
|
+
id: generateNodeID(schema.nodes.body),
|
|
35
|
+
},
|
|
36
|
+
paragraph
|
|
37
|
+
)
|
|
38
|
+
const backmatter = schema.nodes.backmatter.createChecked({
|
|
39
|
+
id: generateNodeID(schema.nodes.backmatter),
|
|
40
|
+
})
|
|
41
|
+
const comments = schema.nodes.comments.createChecked({
|
|
42
|
+
id: generateNodeID(schema.nodes.comments),
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
return schema.nodes.manuscript.createChecked(attrs, [
|
|
46
|
+
title,
|
|
47
|
+
abstracts,
|
|
48
|
+
body,
|
|
49
|
+
backmatter,
|
|
50
|
+
comments,
|
|
51
|
+
])
|
|
52
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* © 2020 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
|
+
|
|
17
|
+
import { v4 as uuid } from 'uuid'
|
|
18
|
+
|
|
19
|
+
import { schema } from '../../schema'
|
|
20
|
+
import { generateNodeID } from '../../transformer'
|
|
21
|
+
|
|
22
|
+
export const DEFAULT_PROFILE_ID =
|
|
23
|
+
'MPUserProfile:0000000000000000000000000000000000000001'
|
|
24
|
+
|
|
25
|
+
const isJATSComment = (node: Node) => {
|
|
26
|
+
return (
|
|
27
|
+
node.nodeType === node.PROCESSING_INSTRUCTION_NODE &&
|
|
28
|
+
node.nodeName === 'AuthorQuery'
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const parseJATSComment = (node: Node): string | undefined => {
|
|
33
|
+
const text = node.textContent
|
|
34
|
+
if (text) {
|
|
35
|
+
const queryText = /queryText="(.+)"/.exec(text)
|
|
36
|
+
return (queryText && queryText[1]) || undefined
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const isHighlightable = (node: Element) => {
|
|
41
|
+
//todo find a better way to do this
|
|
42
|
+
return node.nodeName === 'p'
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const findTarget = (node: Element) => {
|
|
46
|
+
const target = node.closest('ref, kwd-group')
|
|
47
|
+
if (target) {
|
|
48
|
+
return target
|
|
49
|
+
}
|
|
50
|
+
return node
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const markComments = (doc: Document) => {
|
|
54
|
+
const root = doc.getRootNode() as Element
|
|
55
|
+
const queue: Element[] = [root]
|
|
56
|
+
const comments = doc.createElement('comments')
|
|
57
|
+
while (queue.length !== 0) {
|
|
58
|
+
const node = queue.shift()
|
|
59
|
+
if (node) {
|
|
60
|
+
if (isJATSComment(node)) {
|
|
61
|
+
const text = parseJATSComment(node)
|
|
62
|
+
if (text) {
|
|
63
|
+
const id = generateNodeID(schema.nodes.comment)
|
|
64
|
+
let target
|
|
65
|
+
const parent = node.parentNode as Element
|
|
66
|
+
if (isHighlightable(parent)) {
|
|
67
|
+
const marker = createHighlightMarkerElement(doc, id)
|
|
68
|
+
parent.insertBefore(marker, node)
|
|
69
|
+
target = parent
|
|
70
|
+
} else {
|
|
71
|
+
target = findTarget(parent)
|
|
72
|
+
}
|
|
73
|
+
// if the target has no ID, generate one here and rely on
|
|
74
|
+
// updateDocumentIDs to fix it
|
|
75
|
+
if (!target.id) {
|
|
76
|
+
target.id = uuid()
|
|
77
|
+
}
|
|
78
|
+
const comment = createCommentElement(doc, id, target.id, text)
|
|
79
|
+
comments.appendChild(comment)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
node.childNodes.forEach((child) => {
|
|
83
|
+
queue.push(child as Element)
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
doc.documentElement.appendChild(comments)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const createHighlightMarkerElement = (doc: Document, id: string) => {
|
|
92
|
+
const highlightMarker = doc.createElement('highlight-marker')
|
|
93
|
+
highlightMarker.setAttribute('id', id)
|
|
94
|
+
highlightMarker.setAttribute('position', 'point')
|
|
95
|
+
return highlightMarker
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const createCommentElement = (
|
|
99
|
+
doc: Document,
|
|
100
|
+
id: string,
|
|
101
|
+
targetID: string | undefined,
|
|
102
|
+
text: string
|
|
103
|
+
) => {
|
|
104
|
+
const commentElement = doc.createElement('comment')
|
|
105
|
+
commentElement.setAttribute('id', id)
|
|
106
|
+
if (targetID) {
|
|
107
|
+
commentElement.setAttribute('target-id', targetID)
|
|
108
|
+
}
|
|
109
|
+
commentElement.textContent = text
|
|
110
|
+
return commentElement
|
|
111
|
+
}
|