Hello Everyone,
I’m using a Styled Text Editor for my comment thread component. If the character count exceeds 500 characters, I need to trim the text and display a "Show more" link outside the Styled Text Editor.
The problem I’m facing is that the Styled Text Editor stores values with HTML tags, so when I trim the content directly, it can cut through tags and break the markup. This results in invalid HTML and rendering issues.
Has anyone implemented an approach to safely truncate HTML without breaking tags? Any suggestions or best practices would be appreciated.
Discussion posts and replies are publicly visible
That's difficult. I think the markup is pretty simple and uses P-tags for each line. So you could find the next closing P-tag and truncate the text after it.