|
1 | 1 | const urlUtils = require('./urlUtils.js'); |
2 | 2 | const Entities = require('html-entities').AllHtmlEntities; |
3 | 3 | const htmlentities = new Entities().encode; |
4 | | -const htmlparser2 = require('@joplin/fork-htmlparser2'); |
5 | 4 | const { escapeHtml } = require('./string-utils.js'); |
6 | 5 |
|
7 | 6 | // [\s\S] instead of . for multiline matching |
@@ -138,40 +137,6 @@ class HtmlUtils { |
138 | 137 | return output.join(' '); |
139 | 138 | } |
140 | 139 |
|
141 | | - public stripHtml(html: string) { |
142 | | - const output: string[] = []; |
143 | | - |
144 | | - const tagStack: any[] = []; |
145 | | - |
146 | | - const currentTag = () => { |
147 | | - if (!tagStack.length) return ''; |
148 | | - return tagStack[tagStack.length - 1]; |
149 | | - }; |
150 | | - |
151 | | - const disallowedTags = ['script', 'style', 'head', 'iframe', 'frameset', 'frame', 'object', 'base']; |
152 | | - |
153 | | - const parser = new htmlparser2.Parser({ |
154 | | - |
155 | | - onopentag: (name: string) => { |
156 | | - tagStack.push(name.toLowerCase()); |
157 | | - }, |
158 | | - |
159 | | - ontext: (decodedText: string) => { |
160 | | - if (disallowedTags.includes(currentTag())) return; |
161 | | - output.push(decodedText); |
162 | | - }, |
163 | | - |
164 | | - onclosetag: (name: string) => { |
165 | | - if (currentTag() === name.toLowerCase()) tagStack.pop(); |
166 | | - }, |
167 | | - |
168 | | - }, { decodeEntities: true }); |
169 | | - |
170 | | - parser.write(html); |
171 | | - parser.end(); |
172 | | - |
173 | | - return output.join('').replace(/\s+/g, ' '); |
174 | | - } |
175 | 140 | } |
176 | 141 |
|
177 | 142 | export default new HtmlUtils(); |
|
0 commit comments