MOBILE-2465 dom: Revert DOMParser solution to parse HTML

main
Dani Palou 2018-07-10 12:21:32 +02:00
parent c6eb8c24af
commit ca31b58df0
2 changed files with 4 additions and 22 deletions

View File

@ -35,8 +35,6 @@ export class CoreDomUtilsProvider {
'search', 'tel', 'text', 'time', 'url', 'week']; 'search', 'tel', 'text', 'time', 'url', 'week'];
protected INSTANCE_ID_ATTR_NAME = 'core-instance-id'; protected INSTANCE_ID_ATTR_NAME = 'core-instance-id';
protected parser = new DOMParser(); // Parser to treat HTML.
protected matchesFn: string; // Name of the "matches" function to use when simulating a closest call. protected matchesFn: string; // Name of the "matches" function to use when simulating a closest call.
protected instances: {[id: string]: any} = {}; // Store component/directive instances by id. protected instances: {[id: string]: any} = {}; // Store component/directive instances by id.
protected lastInstanceId = 0; protected lastInstanceId = 0;
@ -127,20 +125,13 @@ export class CoreDomUtilsProvider {
/** /**
* Convert some HTML as text into an HTMLElement. This HTML is put inside a div or a body. * Convert some HTML as text into an HTMLElement. This HTML is put inside a div or a body.
* @todo: Try to use DOMParser or similar since this approach will send a request to all embedded media.
* We removed DOMParser solution because it isn't synchronous, document.body wasn't always loaded at start.
* *
* @param {string} html Text to convert. * @param {string} html Text to convert.
* @return {HTMLElement} Element. * @return {HTMLElement} Element.
*/ */
convertToElement(html: string): HTMLElement { convertToElement(html: string): HTMLElement {
if (this.parser) {
const doc = this.parser.parseFromString(html, 'text/html');
// Verify that the doc is valid. In some OS like Android 4.4 only XML parsing is supported, so doc is null.
if (doc) {
return doc.body;
}
}
const element = document.createElement('div'); const element = document.createElement('div');
element.innerHTML = html; element.innerHTML = html;

View File

@ -68,8 +68,6 @@ export class CoreTextUtilsProvider {
{old: /_mmaModWorkshop/g, new: '_AddonModWorkshop'}, {old: /_mmaModWorkshop/g, new: '_AddonModWorkshop'},
]; ];
protected parser = new DOMParser(); // Parser to treat HTML.
constructor(private translate: TranslateService, private langProvider: CoreLangProvider, private modalCtrl: ModalController) { } constructor(private translate: TranslateService, private langProvider: CoreLangProvider, private modalCtrl: ModalController) { }
/** /**
@ -179,20 +177,13 @@ export class CoreTextUtilsProvider {
/** /**
* Convert some HTML as text into an HTMLElement. This HTML is put inside a div or a body. * Convert some HTML as text into an HTMLElement. This HTML is put inside a div or a body.
* This function is the same as in DomUtils, but we cannot use that one because of circular dependencies. * This function is the same as in DomUtils, but we cannot use that one because of circular dependencies.
* @todo: Try to use DOMParser or similar since this approach will send a request to all embedded media.
* We removed DOMParser solution because it isn't synchronous, document.body wasn't always loaded at start.
* *
* @param {string} html Text to convert. * @param {string} html Text to convert.
* @return {HTMLElement} Element. * @return {HTMLElement} Element.
*/ */
protected convertToElement(html: string): HTMLElement { protected convertToElement(html: string): HTMLElement {
if (this.parser) {
const doc = this.parser.parseFromString(html, 'text/html');
// Verify that the doc is valid. In some OS like Android 4.4 only XML parsing is supported, so doc is null.
if (doc) {
return doc.body;
}
}
const element = document.createElement('div'); const element = document.createElement('div');
element.innerHTML = html; element.innerHTML = html;