angular-read-more
angular-read-more copied to clipboard
fix to dom elements truncated with limit
Please review this patch, it fix a very annoying bug.
Bug Explanation: https://github.com/ismarslomic/angular-read-more/issues/6#issuecomment-229992773
Summary:
- It support plain text (ie: without html inside)
- Afaik, the patch doesnt break any feautre of the directive (transparent to user)
- Fix the bug where tags are truncated, which resulted to some content with html not parsed like
" style='text-align:center'> Hey this is a long text that would not appear in less part!!!! </span>
Solution of this patch :
- I use DOMParser recursively parse the content of vm.hmText (ie: data passed to hm-text directive)
- If a text element is encountered, we take it in account to verify that the limit is not reached
- If the limit is reached, the parsing is stopped, and the current element text is truncated. The function return the html parsed until the last tag which reached the limit.
- Plain text are considered as a text element, so no edge case should appear.
Coverage remained the same at 100.0% when pulling 8542c3f41ea66aff22b37249a5f05bda420a50ab on sam2x:fix_dom_elements_truncated into 6faff51cb036d6126b3133e59e0067eb7b546f15 on ismarslomic:master.
Could you also update/add unit tests for this change?
Just merge it, I need that fix!
Note that if you use this fix you cannot have animation transition on text. @ismarslomic i don't know how to add unit test, sry.