fix: added strip html tags for calculating width of line #57
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.
Overview
This PR introduces enhancements to the
measureWidth
function within text truncation component. Previously, the presence of HTML tags in the text could disrupt the accurate measurement of text width, leading to issues such as excess whitespace in lines or incorrect truncation points. To address this, we've implemented a robust method to ignore HTML tags during width calculation, ensuring a more accurate and visually consistent rendering of text.Changes
Stripping HTML Tags: We have added the
stripHtmlTags
function to effectively remove all HTML tags from the text before its width is measured. This function uses a regex pattern to search and replace HTML tags with a single space, preventing them from influencing the width calculation.Width Measurement Enhancement: The
measureWidth
function has been updated to utilizestripHtmlTags
to preprocess the text. This ensures that the text width is calculated without the inclusion of HTML tags, providing a cleaner and more accurate measurement. This is crucial for maintaining the integrity of line breaks and truncation logic in our component.Impact
Enhanced Accuracy: By ensuring that HTML tags do not interfere with text width measurements, the component can now handle texts containing HTML more reliably. This results in better-aligned text and a more visually appealing layout.
Reduced Whitespace Issues: The updated logic helps in minimizing unexpected whitespace within lines, which was previously caused by unaccounted HTML tags in the width calculations.
Example
Before:
After: