Truncates HTML text content to a specified length while preserving HTML structure.
This is an HTML-aware truncation function that walks the DOM tree and preserves
element boundaries while truncating text nodes.
Parameters
text: {maxTextSize:number;text:string}
The HTML string to truncate
Returns string
The truncated HTML string with ellipsis appended if text was truncated
Example
consthtml = '<p>This is a <strong>long</strong> text that needs truncation</p>'; constresult = truncateText({ text:html, maxTextSize:20 }); // result: '<p>This is a <strong>long</strong> te ...</p>'
Truncates HTML text content to a specified length while preserving HTML structure. This is an HTML-aware truncation function that walks the DOM tree and preserves element boundaries while truncating text nodes.