Skip to content

Commit 60c5ff9

Browse files
authored
Merge pull request #1409 from dpalou/MOBILE-2465
MOBILE-2465 dom: Revert DOMParser solution to parse HTML
2 parents c6eb8c2 + ca31b58 commit 60c5ff9

File tree

2 files changed

+4
-22
lines changed

2 files changed

+4
-22
lines changed

src/providers/utils/dom.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ export class CoreDomUtilsProvider {
3535
'search', 'tel', 'text', 'time', 'url', 'week'];
3636
protected INSTANCE_ID_ATTR_NAME = 'core-instance-id';
3737

38-
protected parser = new DOMParser(); // Parser to treat HTML.
39-
4038
protected matchesFn: string; // Name of the "matches" function to use when simulating a closest call.
4139
protected instances: {[id: string]: any} = {}; // Store component/directive instances by id.
4240
protected lastInstanceId = 0;
@@ -127,20 +125,13 @@ export class CoreDomUtilsProvider {
127125

128126
/**
129127
* Convert some HTML as text into an HTMLElement. This HTML is put inside a div or a body.
128+
* @todo: Try to use DOMParser or similar since this approach will send a request to all embedded media.
129+
* We removed DOMParser solution because it isn't synchronous, document.body wasn't always loaded at start.
130130
*
131131
* @param {string} html Text to convert.
132132
* @return {HTMLElement} Element.
133133
*/
134134
convertToElement(html: string): HTMLElement {
135-
if (this.parser) {
136-
const doc = this.parser.parseFromString(html, 'text/html');
137-
138-
// Verify that the doc is valid. In some OS like Android 4.4 only XML parsing is supported, so doc is null.
139-
if (doc) {
140-
return doc.body;
141-
}
142-
}
143-
144135
const element = document.createElement('div');
145136
element.innerHTML = html;
146137

src/providers/utils/text.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ export class CoreTextUtilsProvider {
6868
{old: /_mmaModWorkshop/g, new: '_AddonModWorkshop'},
6969
];
7070

71-
protected parser = new DOMParser(); // Parser to treat HTML.
72-
7371
constructor(private translate: TranslateService, private langProvider: CoreLangProvider, private modalCtrl: ModalController) { }
7472

7573
/**
@@ -179,20 +177,13 @@ export class CoreTextUtilsProvider {
179177
/**
180178
* Convert some HTML as text into an HTMLElement. This HTML is put inside a div or a body.
181179
* This function is the same as in DomUtils, but we cannot use that one because of circular dependencies.
180+
* @todo: Try to use DOMParser or similar since this approach will send a request to all embedded media.
181+
* We removed DOMParser solution because it isn't synchronous, document.body wasn't always loaded at start.
182182
*
183183
* @param {string} html Text to convert.
184184
* @return {HTMLElement} Element.
185185
*/
186186
protected convertToElement(html: string): HTMLElement {
187-
if (this.parser) {
188-
const doc = this.parser.parseFromString(html, 'text/html');
189-
190-
// Verify that the doc is valid. In some OS like Android 4.4 only XML parsing is supported, so doc is null.
191-
if (doc) {
192-
return doc.body;
193-
}
194-
}
195-
196187
const element = document.createElement('div');
197188
element.innerHTML = html;
198189

0 commit comments

Comments
 (0)