Repository navigation
[Add] AttributeValueXHTML.ExtractNormalizedTextFromValue for plain text with normalized whitespace; fixes #92 - #102
Merged
Merged
Conversation
…xt with normalized whitespace; fixes #92 ExtractUnformattedTextFromValue joins the text nodes with a space, so the result has extra spaces around inline elements and keeps the line breaks and indentation of the XHTML source. - Add ExtractNormalizedTextFromValue(bool keepLineBreaks = false): - text is joined as written; outside pre, runs of space, tab, CR and LF are collapsed to one space and each line is trimmed; - block elements and br separate lines, table cells a space; lines are joined with a space or, with keepLineBreaks, a line feed; - pre text is kept as written, without blank lines at its start and end; - non-breaking spaces are kept; HTML named entities such as are decoded, an unknown entity throws an XmlException; - the value is read as an XML fragment (several top-level elements, plain text, undeclared prefixes), with DTD processing prohibited; error positions are those in the value. - ExtractUnformattedTextFromValue is unchanged. - Mention the new method in the README quick-start. 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.



Prerequisites
Description
Fixes #92.
AttributeValueXHTML.ExtractUnformattedTextFromValue()joins the text nodes with a space, so its result has extra spaces around inline elements and keeps the line breaks and indentation of the XHTML source (brew a cup in under 30 seconds .). This adds a second method and leaves the existing one unchanged.New:
ExtractNormalizedTextFromValue(bool keepLineBreaks = false)brew a cup in under 30 seconds.pre, runs of space, tab, carriage return and line feed are collapsed to one space, and each line is trimmed.p,div,li, headings,blockquote,dl/dt/dd,table,tr, ...) andbrseparate lines; table cells are separated by a space. Lines are joined with a space, or with\nwhenkeepLineBreaksis true.preis kept as written (spaces, tabs, indentation, one line per source line); blank lines at its start and end are left out, blank lines inside it are kept only withkeepLineBreaks. andé(which no DTD declares in ReqIF) are decoded withWebUtility.HtmlDecode; an unknown entity throws anXmlExceptionwith its line and position.These rules for
pre, non-breaking spaces and entities were decided during the review.ExtractUnformattedTextFromValueis unchanged; a test pins its output for the example. Note that it still drops HTML named entities silently (cafégivescaf).Tests (
AttributeValueXHTMLTestFixture)The issue example; empty values; source line breaks and indentation; every block and cell element with and without
keepLineBreaks, including upper-case and unprefixed names; whitespace between inline elements andxml:space="preserve"; non-breaking spaces;pre(CRLF and lone CR, indentation, blank lines,br, inline elements, nested and adjacent blocks, emptypre); several top-level elements, plain text, CDATA, comments and processing instructions; attribute values (also with an entity) not in the text; references and HTML entities; unknown entities and malformed values with their exact line and column; DOCTYPE rejected; every XHTML value ofreqifsharpgenerated.reqif.dotnet build -c Release: 0 warnings;dotnet test: 620 passed. The README quick-start mentions the new method.🤖 Generated with Claude Code