mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +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
@@ -76,6 +76,7 @@
|
||||
"@tiptap/starter-kit": "2.26.1",
|
||||
"@tiptap/vue-3": "2.26.1",
|
||||
"@types/haversine": "^1.1.8",
|
||||
"@types/html-to-text": "^9.0.4",
|
||||
"@types/swagger-ui-dist": "^3.30.6",
|
||||
"@unicode/unicode-15.1.0": "^1.6.6",
|
||||
"@vicons/material": "^0.12.0",
|
||||
@@ -161,6 +162,7 @@
|
||||
"heic-convert": "^2.1.0",
|
||||
"hex-array": "^1.0.0",
|
||||
"highlight.js": "^11.11.1",
|
||||
"html-to-text": "^9.0.5",
|
||||
"htmlfy": "^0.8.1",
|
||||
"hyparquet": "^1.9.0",
|
||||
"hyparquet-compressors": "^1.0.0",
|
||||
|
||||
Generated
+13
-3
@@ -116,6 +116,9 @@ dependencies:
|
||||
'@types/haversine':
|
||||
specifier: ^1.1.8
|
||||
version: 1.1.8
|
||||
'@types/html-to-text':
|
||||
specifier: ^9.0.4
|
||||
version: 9.0.4
|
||||
'@types/swagger-ui-dist':
|
||||
specifier: ^3.30.6
|
||||
version: 3.30.6
|
||||
@@ -371,6 +374,9 @@ dependencies:
|
||||
highlight.js:
|
||||
specifier: ^11.11.1
|
||||
version: 11.11.1
|
||||
html-to-text:
|
||||
specifier: ^9.0.5
|
||||
version: 9.0.5
|
||||
htmlfy:
|
||||
specifier: ^0.8.1
|
||||
version: 0.8.1
|
||||
@@ -6824,6 +6830,10 @@ packages:
|
||||
resolution: {integrity: sha512-H1QsLqz6k9QTioutUQUiBiyM4CMmE6A1prXHGotw42j8sN5H/ScC5OxIbcrXnipikrJ5Qn3aozWb9UXBKUscJQ==}
|
||||
dev: true
|
||||
|
||||
/@types/html-to-text@9.0.4:
|
||||
resolution: {integrity: sha512-pUY3cKH/Nm2yYrEmDlPR1mR7yszjGx4DrwPjQ702C4/D5CwHuZTgZdIdwPkRbcuhs7BAh2L5rg3CL5cbRiGTCQ==}
|
||||
dev: false
|
||||
|
||||
/@types/js-beautify@1.14.3:
|
||||
resolution: {integrity: sha512-FMbQHz+qd9DoGvgLHxeqqVPaNRffpIu5ZjozwV8hf9JAGpIOzuAf4wGbRSo8LNITHqGjmmVjaMggTT5P4v4IHg==}
|
||||
dev: true
|
||||
@@ -7447,7 +7457,7 @@ packages:
|
||||
dependencies:
|
||||
'@unhead/dom': 0.5.1
|
||||
'@unhead/schema': 0.5.1
|
||||
'@vueuse/shared': 13.7.0(vue@3.3.4)
|
||||
'@vueuse/shared': 13.8.0(vue@3.3.4)
|
||||
unhead: 0.5.1
|
||||
vue: 3.3.4
|
||||
dev: false
|
||||
@@ -8109,8 +8119,8 @@ packages:
|
||||
- vue
|
||||
dev: false
|
||||
|
||||
/@vueuse/shared@13.7.0(vue@3.3.4):
|
||||
resolution: {integrity: sha512-Wi2LpJi4UA9kM0OZ0FCZslACp92HlVNw1KPaDY6RAzvQ+J1s7seOtcOpmkfbD5aBSmMn9NvOakc8ZxMxmDXTIg==}
|
||||
/@vueuse/shared@13.8.0(vue@3.3.4):
|
||||
resolution: {integrity: sha512-x4nfM0ykW+RmNJ4/1IzZsuLuWWrNTxlTWUiehTGI54wnOxIgI9EDdu/O5S77ac6hvQ3hk2KpOVFHaM0M796Kbw==}
|
||||
peerDependencies:
|
||||
vue: ^3.5.0
|
||||
dependencies:
|
||||
|
||||
@@ -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