diff --git a/package.json b/package.json index 1b889eb9..3acb26b9 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cccf0152..ab694080 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -32,9 +32,6 @@ importers: uuid: specifier: 14.0.0 version: 14.0.0 - w3c-xmlserializer: - specifier: 5.0.0 - version: 5.0.0 devDependencies: '@eslint/eslintrc': specifier: 3.3.5 @@ -150,6 +147,9 @@ importers: vitest: specifier: 4.1.6 version: 4.1.6(@types/node@20.17.46)(@vitest/coverage-v8@4.1.6)(jsdom@29.1.1)(vite@8.0.14(@types/node@20.17.46)(yaml@2.7.1)) + w3c-xmlserializer: + specifier: 5.0.0 + version: 5.0.0 packages: @@ -758,36 +758,42 @@ packages: engines: {node: ^20.19.0 || >=22.12.0} cpu: [arm64] os: [linux] + libc: [glibc] '@rolldown/binding-linux-arm64-musl@1.0.2': resolution: {integrity: sha512-QVLO/czFMdoMFSqlX3bcswcJNm/23r+qoa/jgtmFc/qEp6/jXmIkDjF/XIo8dPfGaiwy1xfQn8o77L79GeXFgw==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [arm64] os: [linux] + libc: [musl] '@rolldown/binding-linux-ppc64-gnu@1.0.2': resolution: {integrity: sha512-hgO5Abm0w5UL6FEa2iFnZqo2KlK7TQ5QhV5x09hujBf7t5KzHQ1VmfPuTpqRy/rNlSxua3eWH374xxiVrP+lcA==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [ppc64] os: [linux] + libc: [glibc] '@rolldown/binding-linux-s390x-gnu@1.0.2': resolution: {integrity: sha512-fy8rXxuYEu602abC8MUNaPjYLIFzReOaEIEMKMUa0rFEUxNpVXhs15KSSQ4qlqSaM7B6rcj9rDZgADh/IGDzLQ==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [s390x] os: [linux] + libc: [glibc] '@rolldown/binding-linux-x64-gnu@1.0.2': resolution: {integrity: sha512-0+bOkiQ779+r1WpoHOWHqncvyySci0vKph+myNDYb+im6meJAzHQXay6oEgnkHuUGouM1LKTZwqKpBow6Kj7CQ==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [x64] os: [linux] + libc: [glibc] '@rolldown/binding-linux-x64-musl@1.0.2': resolution: {integrity: sha512-mjSkrzZK5Qsl0a9d1JgILOiuZOSDTVdKENcSXBoqbzSrspLR/4/IRVDo5wd2GgZjNss/viBFJdeq+j7qH2nypw==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [x64] os: [linux] + libc: [musl] '@rolldown/binding-openharmony-arm64@1.0.2': resolution: {integrity: sha512-1v5vHasdfQAZoEHakBV72LIFAC9JjnymsiKxp+GEr/ma3+NJCPSaYK+qavInOovJkgwFrs7GccX2d6IgDA3Z5w==} @@ -1059,41 +1065,49 @@ packages: resolution: {integrity: sha512-34gw7PjDGB9JgePJEmhEqBhWvCiiWCuXsL9hYphDF7crW7UgI05gyBAi6MF58uGcMOiOqSJ2ybEeCvHcq0BCmQ==} cpu: [arm64] os: [linux] + libc: [glibc] '@unrs/resolver-binding-linux-arm64-musl@1.11.1': resolution: {integrity: sha512-RyMIx6Uf53hhOtJDIamSbTskA99sPHS96wxVE/bJtePJJtpdKGXO1wY90oRdXuYOGOTuqjT8ACccMc4K6QmT3w==} cpu: [arm64] os: [linux] + libc: [musl] '@unrs/resolver-binding-linux-ppc64-gnu@1.11.1': resolution: {integrity: sha512-D8Vae74A4/a+mZH0FbOkFJL9DSK2R6TFPC9M+jCWYia/q2einCubX10pecpDiTmkJVUH+y8K3BZClycD8nCShA==} cpu: [ppc64] os: [linux] + libc: [glibc] '@unrs/resolver-binding-linux-riscv64-gnu@1.11.1': resolution: {integrity: sha512-frxL4OrzOWVVsOc96+V3aqTIQl1O2TjgExV4EKgRY09AJ9leZpEg8Ak9phadbuX0BA4k8U5qtvMSQQGGmaJqcQ==} cpu: [riscv64] os: [linux] + libc: [glibc] '@unrs/resolver-binding-linux-riscv64-musl@1.11.1': resolution: {integrity: sha512-mJ5vuDaIZ+l/acv01sHoXfpnyrNKOk/3aDoEdLO/Xtn9HuZlDD6jKxHlkN8ZhWyLJsRBxfv9GYM2utQ1SChKew==} cpu: [riscv64] os: [linux] + libc: [musl] '@unrs/resolver-binding-linux-s390x-gnu@1.11.1': resolution: {integrity: sha512-kELo8ebBVtb9sA7rMe1Cph4QHreByhaZ2QEADd9NzIQsYNQpt9UkM9iqr2lhGr5afh885d/cB5QeTXSbZHTYPg==} cpu: [s390x] os: [linux] + libc: [glibc] '@unrs/resolver-binding-linux-x64-gnu@1.11.1': resolution: {integrity: sha512-C3ZAHugKgovV5YvAMsxhq0gtXuwESUKc5MhEtjBpLoHPLYM+iuwSj3lflFwK3DPm68660rZ7G8BMcwSro7hD5w==} cpu: [x64] os: [linux] + libc: [glibc] '@unrs/resolver-binding-linux-x64-musl@1.11.1': resolution: {integrity: sha512-rV0YSoyhK2nZ4vEswT/QwqzqQXw5I6CjoaYMOX0TqBlWhojUf8P94mvI7nuJTeaCkkds3QE4+zS8Ko+GdXuZtA==} cpu: [x64] os: [linux] + libc: [musl] '@unrs/resolver-binding-wasm32-wasi@1.11.1': resolution: {integrity: sha512-5u4RkfxJm+Ng7IWgkzi3qrFOvLvQYnPBmjmZQ8+szTK/b31fQCnleNl1GgEt7nIsZRIf5PLhPwT0WM+q45x/UQ==} @@ -2669,24 +2683,28 @@ packages: engines: {node: '>= 12.0.0'} cpu: [arm64] os: [linux] + libc: [glibc] lightningcss-linux-arm64-musl@1.32.0: resolution: {integrity: sha512-UpQkoenr4UJEzgVIYpI80lDFvRmPVg6oqboNHfoH4CQIfNA+HOrZ7Mo7KZP02dC6LjghPQJeBsvXhJod/wnIBg==} engines: {node: '>= 12.0.0'} cpu: [arm64] os: [linux] + libc: [musl] lightningcss-linux-x64-gnu@1.32.0: resolution: {integrity: sha512-V7Qr52IhZmdKPVr+Vtw8o+WLsQJYCTd8loIfpDaMRWGUZfBOYEJeyJIkqGIDMZPwPx24pUMfwSxxI8phr/MbOA==} engines: {node: '>= 12.0.0'} cpu: [x64] os: [linux] + libc: [glibc] lightningcss-linux-x64-musl@1.32.0: resolution: {integrity: sha512-bYcLp+Vb0awsiXg/80uCRezCYHNg1/l3mt0gzHnWV9XP1W5sKa5/TCdGWaR/zBM2PeF/HbsQv/j2URNOiVuxWg==} engines: {node: '>= 12.0.0'} cpu: [x64] os: [linux] + libc: [musl] lightningcss-win32-arm64-msvc@1.32.0: resolution: {integrity: sha512-8SbC8BR40pS6baCM8sbtYDSwEVQd4JlFTOlaD3gWGHfThTcABnNDBda6eTZeqbofalIJhFx0qKzgHJmcPTnGdw==} diff --git a/src/jats/__tests__/jats-exporter.test.ts b/src/jats/__tests__/jats-exporter.test.ts index 72ec95cd..7a16e963 100644 --- a/src/jats/__tests__/jats-exporter.test.ts +++ b/src/jats/__tests__/jats-exporter.test.ts @@ -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' @@ -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 () => { @@ -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 () => { @@ -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') @@ -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) }) @@ -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) }) @@ -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('//ext-link[@ext-link-type="uri"]') expect(link).not.toBeNull() expect(link!.text()).toBe('https//orcid.org/0000-0003-2217-5904') @@ -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) }) @@ -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') @@ -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) @@ -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', diff --git a/src/jats/__tests__/jats-roundtrip.test.ts b/src/jats/__tests__/jats-roundtrip.test.ts index dc01ce10..c89be507 100644 --- a/src/jats/__tests__/jats-roundtrip.test.ts +++ b/src/jats/__tests__/jats-roundtrip.test.ts @@ -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' @@ -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', () => { diff --git a/src/jats/exporter/jats-exporter.ts b/src/jats/exporter/jats-exporter.ts index 56cac31f..cc0a2ef5 100644 --- a/src/jats/exporter/jats-exporter.ts +++ b/src/jats/exporter/jats-exporter.ts @@ -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' @@ -166,7 +165,7 @@ export class JATSExporter { public serializeToJATS = async ( manuscriptNode: ActualManuscriptNode, options: ExportOptions - ): Promise => { + ): Promise => { this.manuscriptNode = manuscriptNode this.populateNodesMap() this.initCiteprocEngine(options) @@ -223,7 +222,7 @@ export class JATSExporter { $article.appendChild($floatsGroup) } await this.rewriteIDs() - return serializeToXML(this.document) + return this.document } private appendChildNodeOfType = ( @@ -616,9 +615,9 @@ export class JATSExporter { const [, bibliography] = this.engine.makeBibliography() const parser = new DOMParser() bibliography.forEach((item) => { - const fragment = `` + )}` const $ref = parser .parseFromString(fragment, 'text/xml') .querySelector('ref') diff --git a/src/schema/types.ts b/src/schema/types.ts index f9888ad5..161a3761 100644 --- a/src/schema/types.ts +++ b/src/schema/types.ts @@ -190,21 +190,11 @@ export type ManuscriptTemplate = { hiddenNodeTypes?: string[] } -export interface UserProfile { - _id: string - userID: string - connectID: string -} - -export interface Project { - _id: string - owners: string[] - writers: string[] - editors?: string[] - annotators?: string[] - proofers?: string[] - viewers: string[] - updatedAt: number +export interface User { + id: string + displayName: string + firstName?: string + lastName?: string } export interface Bundle { @@ -214,23 +204,6 @@ export interface Bundle { } } -export enum ManuscriptActions { - handleSuggestion = 'handleSuggestion', - rejectOwnSuggestion = 'rejectOwnSuggestion', - handleOwnComments = 'handleOwnComments', - handleOthersComments = 'handleOthersComments', - resolveOwnComment = 'resolveOwnComment', - resolveOthersComment = 'resolveOthersComment', - createComment = 'createComment', - canEditFiles = 'canEditFiles', - editArticle = 'editArticle', - formatArticle = 'formatArticle', - editMetadata = 'editMetadata', - editCitationsAndRefs = 'editCitationsAndRefs', - seeEditorToolbar = 'seeEditorToolbar', - seeReferencesButtons = 'seeReferencesButtons', -} - export type MarkRule = ParseRule & { mark: Marks | null } export type NodeRule = ParseRule & { node?: Nodes | null }