Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
"prosemirror-tables": "1.7.1",
"prosemirror-utils": "1.2.2",
"semver": "7.7.4",
"uuid": "14.0.0",
"w3c-xmlserializer": "5.0.0"
"uuid": "14.0.0"
},
"devDependencies": {
"@eslint/eslintrc": "3.3.5",
Expand Down Expand Up @@ -80,7 +79,8 @@
"prosemirror-state": "1.4.3",
"prosemirror-view": "1.39.2",
"rimraf": "6.1.3",
"typescript": "6.0.3"
"typescript": "6.0.3",
"w3c-xmlserializer": "5.0.0"
},
"engines": {
"node": ">=22"
Expand Down
24 changes: 21 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 25 additions & 19 deletions src/jats/__tests__/jats-exporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import { Element as XMLElement, parseXml } from 'libxmljs2'
import serializeToXML from 'w3c-xmlserializer'

import { JATSExporter } from '../exporter/jats-exporter'
import { Version } from '../exporter/jats-versions'
Expand All @@ -40,11 +41,11 @@ describe('JATS exporter', () => {
const transformer = new JATSExporter()
const input = await readAndParseFixture('jats-example-full.xml')
const node = parseJATSArticle(input, sectionCategories)
const result = await transformer.serializeToJATS(node, {
const document = await transformer.serializeToJATS(node, {
csl: DEFAULT_CSL_OPTIONS,
})

expect(result).toMatchSnapshot('jats-export')
expect(serializeToXML(document)).toMatchSnapshot('jats-export')
})

test('export with & and < in bibliography metadata', async () => {
Expand All @@ -61,23 +62,25 @@ describe('JATS exporter', () => {

biblio!.attrs.title += ' & Sons 55 < 135'

const result = await transformer.serializeToJATS(node, {
const document = await transformer.serializeToJATS(node, {
csl: DEFAULT_CSL_OPTIONS,
})

expect(result).toMatchSnapshot('jats-export-with-xml-unsafe-in-biblios')
expect(serializeToXML(document)).toMatchSnapshot(
'jats-export-with-xml-unsafe-in-biblios'
)
})

test('export v1.1', async () => {
const transformer = new JATSExporter()
const input = await readAndParseFixture('jats-example-full.xml')
const node = parseJATSArticle(input, sectionCategories)
const result = await transformer.serializeToJATS(node, {
const document = await transformer.serializeToJATS(node, {
csl: DEFAULT_CSL_OPTIONS,
version: '1.1',
})

expect(result).toMatchSnapshot('jats-export-1.1')
expect(serializeToXML(document)).toMatchSnapshot('jats-export-1.1')
})

test('export unknown version', async () => {
Expand All @@ -96,9 +99,10 @@ describe('JATS exporter', () => {
const transformer = new JATSExporter()
const input = await readAndParseFixture('jats-tables-example.xml')
const node = parseJATSArticle(input, sectionCategories)
const xml = await transformer.serializeToJATS(node, {
const document = await transformer.serializeToJATS(node, {
csl: DEFAULT_CSL_OPTIONS,
})
const xml = serializeToXML(document)

const resultDoc = parseXMLWithDTD(xml)
const tableWrapFoot = resultDoc.get('//table-wrap/table-wrap-foot')
Expand All @@ -111,11 +115,11 @@ describe('JATS exporter', () => {
const transformer = new JATSExporter()
const input = await readAndParseFixture('jats-import.xml')
const node = parseJATSArticle(input, sectionCategories)
const xml = await transformer.serializeToJATS(node, {
const document = await transformer.serializeToJATS(node, {
csl: DEFAULT_CSL_OPTIONS,
})

const { errors } = parseXMLWithDTD(xml)
const { errors } = parseXMLWithDTD(serializeToXML(document))

expect(errors).toHaveLength(0)
})
Expand All @@ -124,10 +128,10 @@ describe('JATS exporter', () => {
const transformer = new JATSExporter()
const input = await readAndParseFixture('jats-document.xml')
const node = parseJATSArticle(input, sectionCategories)
const xml = await transformer.serializeToJATS(node, {
const document = await transformer.serializeToJATS(node, {
csl: DEFAULT_CSL_OPTIONS,
})
const { errors } = parseXMLWithDTD(xml)
const { errors } = parseXMLWithDTD(serializeToXML(document))

expect(errors).toHaveLength(0)
})
Expand All @@ -136,11 +140,11 @@ describe('JATS exporter', () => {
const transformer = new JATSExporter()
const input = await readAndParseFixture('jats-import.xml')
const node = parseJATSArticle(input, sectionCategories)
const xml = await transformer.serializeToJATS(node, {
const document = await transformer.serializeToJATS(node, {
csl: DEFAULT_CSL_OPTIONS,
})

const output = parseXMLWithDTD(xml)
const output = parseXMLWithDTD(serializeToXML(document))
const link = output.get<XMLElement>('//ext-link[@ext-link-type="uri"]')
expect(link).not.toBeNull()
expect(link!.text()).toBe('https//orcid.org/0000-0003-2217-5904')
Expand All @@ -159,11 +163,11 @@ describe('JATS exporter', () => {
const transformer = new JATSExporter()
const input = await readAndParseFixture('jats-example-doc.xml')
const node = parseJATSArticle(input, sectionCategories)
const xml = await transformer.serializeToJATS(node, {
const document = await transformer.serializeToJATS(node, {
csl: DEFAULT_CSL_OPTIONS,
})

const { errors } = parseXMLWithDTD(xml)
const { errors } = parseXMLWithDTD(serializeToXML(document))

expect(errors).toHaveLength(0)
})
Expand All @@ -172,10 +176,10 @@ describe('JATS exporter', () => {
const transformer = new JATSExporter()
const input = await readAndParseFixture('jats-import.xml')
const node = parseJATSArticle(input, sectionCategories)
const xml = await transformer.serializeToJATS(node, {
const document = await transformer.serializeToJATS(node, {
csl: DEFAULT_CSL_OPTIONS,
})
const resultDoc = parseXMLWithDTD(xml)
const resultDoc = parseXMLWithDTD(serializeToXML(document))
const supplementaryMaterial = resultDoc.get('//supplementary-material')
if (!supplementaryMaterial) {
throw new Error('No supplementary material found')
Expand Down Expand Up @@ -215,9 +219,10 @@ describe('JATS exporter', () => {
n.attrs.rids.forEach((rid: string) => citedIDs.add(rid))
}
})
const xml = await new JATSExporter().serializeToJATS(node, {
const document = await new JATSExporter().serializeToJATS(node, {
csl: DEFAULT_CSL_OPTIONS,
})
const xml = serializeToXML(document)
const refCount = parseXMLWithDTD(xml).find('//ref-list/ref').length
expect(refCount).toBe(bibliographyItemIDs.size)
const { errors } = parseXMLWithDTD(xml)
Expand All @@ -228,9 +233,10 @@ describe('JATS exporter', () => {
const transformer = new JATSExporter()
const input = await readAndParseFixture('jats-fn-group.xml')
const node = parseJATSArticle(input, sectionCategories)
const xml = await transformer.serializeToJATS(node, {
const document = await transformer.serializeToJATS(node, {
csl: DEFAULT_CSL_OPTIONS,
})
const xml = serializeToXML(document)
const footnoteCategories = [
'con',
'deceased',
Expand Down
4 changes: 3 additions & 1 deletion src/jats/__tests__/jats-roundtrip.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import { parseXml } from 'libxmljs2'
import serializeToXML from 'w3c-xmlserializer'

import { JATSExporter } from '../exporter/jats-exporter'
import { parseJATSArticle } from '../importer/parse-jats-article'
Expand All @@ -36,9 +37,10 @@ const roundtrip = async (filename: string) => {
const node = parseJATSArticle(doc, sectionCategories)

const exporter = new JATSExporter()
return await exporter.serializeToJATS(node, {
const document = await exporter.serializeToJATS(node, {
csl: DEFAULT_CSL_OPTIONS,
})
return serializeToXML(document)
}

describe('JATS roundtrip', () => {
Expand Down
9 changes: 4 additions & 5 deletions src/jats/exporter/jats-exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import * as Citeproc from 'citeproc'
import { DOMOutputSpec, DOMSerializer, type NodeType } from 'prosemirror-model'
import { findChildrenByAttr, findChildrenByType } from 'prosemirror-utils'
import serializeToXML from 'w3c-xmlserializer'

import { buildCiteprocCitation } from '../../lib/citeproc'
import { CreditRoleUrls } from '../../lib/credit-roles'
Expand Down Expand Up @@ -166,7 +165,7 @@ export class JATSExporter {
public serializeToJATS = async (
manuscriptNode: ActualManuscriptNode,
options: ExportOptions
): Promise<string> => {
): Promise<Document> => {
Comment on lines 165 to +168
this.manuscriptNode = manuscriptNode
this.populateNodesMap()
this.initCiteprocEngine(options)
Expand Down Expand Up @@ -223,7 +222,7 @@ export class JATSExporter {
$article.appendChild($floatsGroup)
}
await this.rewriteIDs()
return serializeToXML(this.document)
return this.document
}

private appendChildNodeOfType = (
Expand Down Expand Up @@ -616,9 +615,9 @@ export class JATSExporter {
const [, bibliography] = this.engine.makeBibliography()
const parser = new DOMParser()
bibliography.forEach((item) => {
const fragment = `<template xmlns:xlink="${XLINK_NAMESPACE}">${sanitizeXmlString(
const fragment = `<wrapper xmlns:xlink="${XLINK_NAMESPACE}">${sanitizeXmlString(
item
)}</template>`
)}</wrapper>`
const $ref = parser
.parseFromString(fragment, 'text/xml')
.querySelector('ref')
Expand Down
Loading