Skip to content

LEAN-6048: Return a Document from serializeToJATS; fix bibliography ref parsing under linkedom - #361

Open
mnatsheh wants to merge 3 commits into
masterfrom
LEAN-6048
Open

mnatsheh wants to merge 3 commits into
masterfrom
LEAN-6048

Conversation

@mnatsheh

Copy link
Copy Markdown
Contributor

Summary

  • serializeToJATS() now returns the built Document instead of a serialized string, so each consumer can choose its own serialization strategy (real w3c-xmlserializer under Node/jsdom, or Document#toString() under linkedom-based runtimes like Cloudflare Workers).
  • w3c-xmlserializer moves from a runtime dependency to a devDependency — it's now only used by this package's own test suite to stringify the returned Document for assertions.
  • The <template> wrapper tag used when parsing each citeproc-generated bibliography entry is replaced with <wrapper>, since linkedom applies HTML <template>'s special content-fragment handling to it even during XML parsing, which broke extracting the nested <ref> back out.

Test plan

  • pnpm typecheck passes
  • pnpm test — 74/74 pass
  • Verified against manuscripts-cf-worker (linked locally): its export-jats test suite passes end-to-end once it consumes this change and drops its own patched w3c-xmlserializer

🤖 Generated with Claude Code

…y ref parsing

serializeToJATS() now returns the built Document instead of an
already-serialized string, letting each consumer choose its own
serialization strategy. Callers under Node (real DOM) can use the real
w3c-xmlserializer; manuscripts-cf-worker's linkedom-based DOM can just
call Document#toString(). This removes the need for cf-worker's patched
w3c-xmlserializer, whose spec-correct namespace resolution never worked
against linkedom's DOM model.

w3c-xmlserializer moves from a runtime dependency to a devDependency,
used only by this package's own test suite (which runs under jsdom) to
stringify the returned Document for snapshot/content assertions.

Also replaces the <template> wrapper tag used when parsing each
citeproc-generated bibliography entry with <wrapper>: <template> is a
recognized HTML special element, and linkedom applies its special
content-fragment handling to it even during XML parsing, which breaks
extracting the nested <ref> back out.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings September 18, 2026 18:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The public API now returns a Document from serializeToJATS(), which is a breaking change and currently leaves the method naming/consumer-facing documentation inconsistent, increasing the risk of downstream misuse.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This PR adjusts the JATS export surface to return a DOM Document from JATSExporter.serializeToJATS() (instead of an XML string), and updates bibliography parsing to avoid linkedom’s special <template> handling so <ref> extraction works reliably across runtimes.

Changes:

  • Change serializeToJATS() to return the built Document rather than a serialized XML string.
  • Update citeproc bibliography entry parsing wrapper from <template> to <wrapper> to restore <ref> extraction under linkedom.
  • Move w3c-xmlserializer usage into tests (and to devDependencies) for snapshot/DTD assertions.
File summaries
File Description
src/jats/exporter/jats-exporter.ts Return a DOM Document from serializeToJATS() and adjust bibliography <ref> parsing wrapper element.
src/jats/tests/jats-roundtrip.test.ts Serialize returned Document with w3c-xmlserializer for roundtrip snapshot + DTD validation.
src/jats/tests/jats-exporter.test.ts Serialize returned Document with w3c-xmlserializer for snapshots and DTD assertions.
package.json Move w3c-xmlserializer from dependencies to devDependencies.
pnpm-lock.yaml Lockfile updates reflecting dependency move and related resolution metadata changes.
Review details

Files not reviewed (1)

  • pnpm-lock.yaml: Generated file
  • Files reviewed: 4/5 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 165 to +168
public serializeToJATS = async (
manuscriptNode: ActualManuscriptNode,
options: ExportOptions
): Promise<string> => {
): Promise<Document> => {
mnatsheh and others added 2 commits September 21, 2026 14:04
permittedActions is now a single flat string[] with no distinction
between package-level enums — the merged set of actions lives in
article-editor's local capabilities.tsx instead (alongside
body-editor's former Actions enum, removed the same way).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Project had zero real consumers anywhere outside manuscripts-api
(explicitly out of scope). UserProfile's only real internal usage was a
string ID prefix, not the type itself; its actual consumers were all in
host apps, which now use a plain User shape ({id, displayName, firstName?,
lastName?}) sourced entirely from props rather than fetched — connectID
is dropped since nothing ever read it.

manuscripts-api has live imports of both Project and UserProfile
(ProjectController.ts, UserService.ts, etc.) and will need its own
follow-up migration once it moves off these.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants