Add keep_order option to preserve HTML element sequence instead of grouping by type#9
Draft
Add keep_order option to preserve HTML element sequence instead of grouping by type#9
Conversation
…ping by type Co-authored-by: MrDebugger <25988388+MrDebugger@users.noreply.github.com>
Co-authored-by: MrDebugger <25988388+MrDebugger@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] new feature request: option to keep elements order
Add keep_order option to preserve HTML element sequence instead of grouping by type
Aug 3, 2025
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.
This PR implements a new
keep_orderparameter for theBS2Jsonclass that preserves the original order of HTML elements instead of grouping them by type. This addresses the need for document generation workflows that require maintaining the structural flow of HTML content.Problem
The current implementation groups all elements of the same type together, which loses the original document structure:
Solution
Added an optional
keep_orderparameter that preserves element sequence:Key Features
keep_order=False){"h3": "chapter 1"})BS2Jsonclass and tag extension methodsImplementation Details
to_json()method to handle ordered output whenkeep_order=TrueThis enables use cases like feeding structured JSON to document generators (e.g., python-docx) while maintaining the original document flow and semantic relationships between adjacent elements.
Fixes #8.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.