Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
renderjs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boris Kocherov
renderjs
Commits
72914726
Commit
72914726
authored
Jul 09, 2013
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use native Firefox DOMParser.
Provide a better html parsing, to continue working on renderJS itself.
parent
6d43204c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
5 deletions
+23
-5
renderjs.js
renderjs.js
+9
-5
test/renderjs_test2.js
test/renderjs_test2.js
+14
-0
No files found.
renderjs.js
View file @
72914726
/*! RenderJs v0.2 */
/*! 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 */
/*jslint evil: true, indent: 2, maxerr: 3, maxlen: 79 */
"
use strict
"
;
"
use strict
"
;
/*
/*
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
* http://www.renderjs.org/documentation
* http://www.renderjs.org/documentation
*/
*/
(
function
(
document
,
window
,
$
)
{
(
function
(
document
,
window
,
$
,
DOMParser
)
{
var
gadget_model_dict
=
{},
var
gadget_model_dict
=
{},
gadget_scope_dict
=
{},
gadget_scope_dict
=
{},
...
@@ -362,8 +362,12 @@
...
@@ -362,8 +362,12 @@
};
};
if
(
html
.
constructor
===
String
)
{
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
();
settings
.
title
=
parsed_xml
.
find
(
'
head > title
'
).
first
().
text
();
// XXX Manage relative URL during extraction of URLs
// XXX Manage relative URL during extraction of URLs
...
@@ -501,7 +505,7 @@
...
@@ -501,7 +505,7 @@
// // XXX Load gadgets defined in the html
// // XXX Load gadgets defined in the html
// $('body').renderJS('loadGadgetFromDom');
// $('body').renderJS('loadGadgetFromDom');
}(
document
,
window
,
jQuery
));
}(
document
,
window
,
jQuery
,
DOMParser
));
/**
/**
...
...
test/renderjs_test2.js
View file @
72914726
...
@@ -253,6 +253,20 @@
...
@@ -253,6 +253,20 @@
deepEqual
(
settings
.
required_js_list
,
[],
"
JS not found
"
);
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
// declareGadgetKlass
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment