Commit 72914726 authored by Romain Courteaud's avatar Romain Courteaud

Use native Firefox DOMParser.

Provide a better html parsing, to continue working on renderJS itself.
parent 6d43204c
/*! RenderJs v0.2 */
/*global $, jQuery, localStorage, jIO, window, document */
/*global $, jQuery, localStorage, jIO, window, document, DOMParser */
/*jslint evil: true, indent: 2, maxerr: 3, maxlen: 79 */
"use strict";
/*
......@@ -7,7 +7,7 @@
* http://www.renderjs.org/documentation
*/
(function (document, window, $) {
(function (document, window, $, DOMParser) {
var gadget_model_dict = {},
gadget_scope_dict = {},
......@@ -362,8 +362,12 @@
};
if (html.constructor === String) {
parsed_xml = $($.parseXML(html));
// https://developer.mozilla.org/en-US/docs/HTML_in_XMLHttpRequest
// https://developer.mozilla.org/en-US/docs/Web/API/DOMParser
// https://developer.mozilla.org/en-US/docs/Code_snippets/HTML_to_DOM
// parsed_xml = $($.parseXML(html));
// parsed_xml = $('<div/>').html(html);
parsed_xml = $((new DOMParser()).parseFromString(html, "text/html"));
settings.title = parsed_xml.find('head > title').first().text();
// XXX Manage relative URL during extraction of URLs
......@@ -501,7 +505,7 @@
// // XXX Load gadgets defined in the html
// $('body').renderJS('loadGadgetFromDom');
}(document, window, jQuery));
}(document, window, jQuery, DOMParser));
/**
......
......@@ -253,6 +253,20 @@
deepEqual(settings.required_js_list, [], "JS not found");
});
test('Non valid XML (HTML in fact...)', function () {
// Check default value returned by parseGadgetHTML
deepEqual(renderJS.parseGadgetHTML('<!doctype html><html><head>' +
'<title>Test non valid XML</title>' +
'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' +
'</head><body><p>Non valid XML</p></body></html>'), {
title: "Test non valid XML",
interface_list: [],
required_css_list: [],
required_js_list: [],
html: "<p>Non valid XML</p>",
});
});
/////////////////////////////////////////////////////////////////
// declareGadgetKlass
/////////////////////////////////////////////////////////////////
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment