sr-npm 1.7.953 → 1.7.954
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/public/utils.js +12 -12
package/package.json
CHANGED
package/public/utils.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
|
|
2
2
|
function htmlToText(html) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
|
|
4
|
+
// Let the browser decode ALL HTML entities automatically
|
|
5
|
+
const textarea = document.createElement('textarea');
|
|
6
|
+
console.log("textarea: ",textarea);
|
|
7
|
+
textarea.innerHTML = html;
|
|
8
|
+
console.log("textarea.innerHTML: ",textarea.innerHTML);
|
|
9
|
+
let decoded = textarea.value;
|
|
10
|
+
console.log("decoded: ",decoded);
|
|
11
|
+
// Now clean up the HTML tags and formatting
|
|
12
|
+
let text = decoded
|
|
7
13
|
.replace(/<br\s*\/?>/gi, '\n')
|
|
8
14
|
.replace(/<\/?(p|div|h[1-6])\s*\/?>/gi, '\n')
|
|
9
15
|
.replace(/<li[^>]*>/gi, '• ')
|
|
10
16
|
.replace(/<\/li>/gi, '\n')
|
|
11
|
-
.replace(/<[^>]*>/g, '')
|
|
12
|
-
|
|
13
|
-
.replace(/</g, '<')
|
|
14
|
-
.replace(/>/g, '>')
|
|
15
|
-
.replace(/"/g, '"')
|
|
16
|
-
.replace(/'/g, "'")
|
|
17
|
-
.replace(/ /g, ' ');
|
|
18
|
-
|
|
17
|
+
.replace(/<[^>]*>/g, '');
|
|
18
|
+
console.log("text: ",text);
|
|
19
19
|
// Clean up whitespace
|
|
20
20
|
return text.replace(/\n\s*\n+/g, '\n\n').replace(/[ \t]+\n/g, '\n').trim();
|
|
21
21
|
}
|