feat: expose parsed NSML body as bodyNodes - #11
Open
rjmunro wants to merge 3 commits into
Open
Conversation
- Add NsmlNode types and optional bodyNodes on INewsStory - Convert already-parsed <body> children instead of discarding the tree - Keep body string for backwards compatibility
- Refresh README examples for @tv2media/inews Promise API - Document INewsStory fields including body vs bodyNodes
There was a problem hiding this comment.
Pull request overview
This PR extends the parsed story output to expose the already-parsed NSML <body> children as a JSON-serializable node tree (bodyNodes), allowing downstream consumers to traverse <pi>, <cc>, anchors, etc. without re-parsing the legacy body HTML string.
Changes:
- Add
NsmlNodetypes and a new optionalINewsStory.bodyNodes?: NsmlNode[]field. - Populate
bodyNodesduring NSML parsing (while keeping the legacybodystring unchanged). - Add tests for
bodyNodesparsing and update the README to document the new shape.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/types/inews.ts | Introduces NsmlNode types and adds bodyNodes to INewsStory. |
| src/inewsStoryParser.ts | Builds and assigns bodyNodes from the existing htmlparser DOM during parsing. |
| src/tests/iNewsStoryParser.spec.ts | Adds coverage for bodyNodes parsing (including entity unescaping and empty body). |
| README.md | Updates usage/docs and documents the new bodyNodes field and structure. |
Comments suppressed due to low confidence (2)
README.md:52
- This snippet also uses top-level
awaitalongsiderequire(...), which won’t run in a standard CommonJS script. Wrap in an async IIFE so users can copy/paste the example without additional setup.
const inewsQueue = 'YOUR.QUEUE.HERE'
const dirList = await conn.list(inewsQueue)
for (const storyFile of dirList) {
const story = await conn.story(inewsQueue, storyFile.file)
console.log(story)
}
README.md:63
- This example uses top-level
awaitwhile the README usesrequire(...)earlier (CommonJS). Wrap in an async IIFE (or use.then) to keep the example executable.
const inewsQueue = 'YOUR.QUEUE.HERE'
const dirList = await conn.list(inewsQueue)
for (const storyFile of dirList) {
const storyNsml = await conn.storyNsml(inewsQueue, storyFile.file)
console.log(storyNsml)
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+36
to
+39
| const dirList = await conn.list('YOUR.QUEUE.HERE') | ||
| for (const story of dirList) { | ||
| console.log(story.file) | ||
| } |
- Explain why CDATA markers are stripped and the semantic cost - Contrast whole-string body unescape with leaf-only bodyNodes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
About the Contributor
This pull request is posted on behalf of SVT.
Type of Contribution
This is a feature
Current Behavior
story()parses NSML and exposes<body>only as a re-serialized HTML string (body). Consumers (gateways/blueprints) must re-parse that string with regex or an HTML parser to read<pi>,<cc>, cue anchors, etc.New Behavior
INewsStoryalso includesbodyNodes?: NsmlNode[]— a JSON-serializable tree of the parsed<body>children, built from the DOM already produced byhtmlparser(no second parse).bodyis unchanged for backwards compatibilitybodyNodesbody)@tv2media/inews, Promise API, andbodyNodesTesting Instructions
yarn testNew cases cover a typical body with
<pi>/<a>/<cc>(including entity unescaping) and an empty<body>.Other Information
Follow-up for Sofie: bump
sofie-inews-ftp-gatewayto this revision and switch blueprints from regex onbodyto traversingbodyNodes. Gateway code that mutatesbodyas a string (e.g. layout cue link injection) should keepbodyNodesin sync or stop relying on the string for those edits.Status