Fixed ReplaceStep to perform a real tree replace - #12
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates Prosereflect’s transform pipeline so ReplaceStep performs a true tree-structured replace (rather than rebuilding via fragments), and ensures transformed documents remain traversable with correctly-typed node content.
Changes:
- Implemented
Node#replaceand switchedReplaceStep#applyto use it, rejecting unsupported slice open boundaries and fixinginvertto return aSlice. - Updated multiple transform steps to rebuild documents via
Node#copysodoc.contentcontains nodes (not a wrappedFragment). - Added
leaf?/inline?node semantics and extensive specs covering replace edge cases (leaf handling, text merging, boundary insertion behavior).
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| spec/prosereflect/transform/step_content_spec.rb | Adds regression coverage ensuring step results produce traversable documents with node content. |
| spec/prosereflect/transform/replace_spec.rb | Expands ReplaceStep specs to validate correct text outcomes, node_size stability, and leaf/boundary behaviors. |
| lib/prosereflect/transform/replace_step.rb | Switches ReplaceStep to delegate to doc.replace, adds open-boundary rejection, and wraps inversion content in a Slice. |
| lib/prosereflect/transform/replace_around_step.rb | Uses doc.copy to rebuild docs without fragment-wrapping issues. |
| lib/prosereflect/transform/mark_step.rb | Uses doc.copy when applying/removing marks to preserve correct node content. |
| lib/prosereflect/transform/attr_step.rb | Uses doc.copy when applying attrs to preserve correct node content. |
| lib/prosereflect/node.rb | Adds leaf?, inline?, and the core replace implementation used by ReplaceStep. |
| lib/prosereflect/text.rb | Marks Text as inline to support boundary resolution decisions. |
| lib/prosereflect/hard_break.rb | Declares hard_break as an inline leaf for correct replace insertion semantics. |
| lib/prosereflect/image.rb | Declares image as an inline leaf for correct replace insertion semantics. |
| lib/prosereflect/horizontal_rule.rb | Declares horizontal_rule as a leaf for correct replace insertion semantics. |
| lib/prosereflect/user.rb | Declares user mention as an inline leaf for correct replace insertion semantics. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Metanorma PR checklist
Related to lutaml/lutaml-model#720
This PR fixes failures in https://github.com/lutaml/lutaml-model/actions/runs/29395937178/job/87293331371?pr=720