Repository navigation
Conversation
lxml's text_content() adds no separator after block elements, so words from adjacent blocks run together when the XHTML has no whitespace between the tags. Add reqif.helpers.xhtml.xhtml_to_plain_text, which breaks the text after block elements and <br/> and collapses the remaining whitespace. keep_paragraphs=True keeps the paragraph and line breaks for callers such as StrictDoc. Use the helper in the README and in the requirement text example, and add a requirement with compact XHTML to the example input. Closes strictdoc-project#235 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Hq1ACTsK85bRrY28fUQ7b3
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.
Closes #235.
This adds
reqif.helpers.xhtml.xhtml_to_plain_text(xhtml, keep_paragraphs=False), based on the sketch in the issue:fragment_fromstring(..., create_parent="div"), so several top-level elements, plain text and an empty value all work.BLOCK_TAGSset from the issue) and<br/>mark a break before and after their text. Comments are skipped.First. Second.,Line one Line two, and the compact list from the issue reads the same as the indented one.For the open question about StrictDoc,
keep_paragraphs=Trueseparates the blocks with a blank line and starts a new line at each<br/>, for exampleThe system shall lock after:\n\n5 attempts, or\n\nadmin request.Nested blocks do not add extra blank lines. Happy to change the shape of that output if StrictDoc needs something different.Following the follow-up list in the issue, the README recipe and
examples/05_extract_requirement_text/script.pynow use the helper, andinput.reqifhas a third requirement whose XHTML has no whitespace between the tags. The old recipe would print...end a session after:15 minutes without activity, ora logout.for it.The unit tests cover the values from the table in the issue. Locally, the unit tests pass and all integration tests pass except
commands/dump/01_basic_exampleandexamples/04_convert_reqif_to_json, which fail the same way onmainin my environment.I used Claude to help write and test this change.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Hq1ACTsK85bRrY28fUQ7b3