Repository navigation
Conversation
With preserveOrder and format, arrToStr() decided how to format an element's content by looking at the generated string. That wrote a whitespace-only line, left the closing tag on the line of text after a comment, did not indent text before a tag, and added whitespace to content that ends with ">" but has no child tag, such as CDATA, text with processEntities: false and stop nodes. The content is now written on lines of its own only if a child is an element, a comment or a processing instruction, and never for a stop node. Fixes NaturalIntelligence#31 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes #31
Problem
With
preserveOrder: trueandformat: true,arrToStr()decided how to format an element's content by looking at the generated string (endsWith(">"),includes("/>"),includes("</")). That wrote a whitespace-only line, left the closing tag on the line of text after a comment, did not indent text before a tag, and added whitespace to content that ends with>but has no child tag: CDATA, text withprocessEntities: false, and the raw content of stop nodes. The issue has examples of each.Change
src/orderedJs2Xml.js: a new helper,hasMarkupChild(), checks whether a child is an element, a comment or a processing instruction. Only then is the content written on lines of its own, with a line break and indentation added before a leading text or CDATA child. Stop nodes are never formatted. Everything else is written inline. This replaces the two branches that inspected the string.spec/j2x_ordered_spec.js: one spec per case from the issue. All six fail without the change.All existing specs pass unchanged.
eslintreports two errors inspec/j2x_ordered_spec.js(formatandisAttributeunused) that were there before this change.The leading line break of the output is a separate question (#30) and not changed here.
Type
🤖 Generated with Claude Code