mirror of
https://github.com/sharevb/it-tools.git
synced 2026-12-04 18:35:09 +03:00
fix(Extract Text From HTML): use html-to-text for better result
Fix #1035
This commit is contained in:
1 parent
1234dca5ff
commit
91f554845a
3 files changed
+18
-7
No files matched your search
@@ -1,3 +1,5 @@
|
||||
import { convert } from 'html-to-text';
|
||||
|
||||
function validateHtml(value: string) {
|
||||
try {
|
||||
new DOMParser().parseFromString(value, 'text/html');
|
||||
@@ -13,10 +15,7 @@ function validateHtml(value: string) {
|
||||
}
|
||||
|
||||
function getTextFromHtml(value: string) {
|
||||
const element = document.createElement('div');
|
||||
element.innerHTML = value;
|
||||
const text = element?.innerText || element?.textContent || '';
|
||||
return text.replace(/\s+/g, ' ');
|
||||
return convert(value);
|
||||
}
|
||||
|
||||
export { validateHtml, getTextFromHtml };
|
||||
Reference in new issue
Block a user