Commit 677c64a2 authored by Alexandra Rogova's avatar Alexandra Rogova

test : remove styling in HTML while parsing

parent a86a462d
......@@ -3,7 +3,7 @@
(function(window, RSVP, rJS, jIO) {
"use strict";
rJS(window)
.declareAcquiredMethod("get_model", "get_model")
.declareMethod("read_file", function(link) {
......@@ -39,7 +39,7 @@
xmlhttp.send();
});
})
.declareMethod("parse", function(local_cur_text, storage) {
var title_start = local_cur_text.indexOf("<title>") + 7,
title_end = local_cur_text.indexOf("</title>"),
......@@ -47,7 +47,7 @@
link_end = local_cur_text.indexOf("</link>"),
body_start = local_cur_text.indexOf("<description>"),
body_end = local_cur_text.indexOf("</description>") + 14;
return this.parse_body(local_cur_text.slice(body_start, body_end))
return this.remove_css(local_cur_text.slice(body_start, body_end))
.push (function(result){
return storage.put({
"title": local_cur_text.slice(title_start, title_end),
......@@ -56,19 +56,28 @@
});
});
})
.declareMethod("parse_body", function(body){
/*var before,
after;
while (body.indexOf("&lt;span style") > -1){
before = body.slice(0, body.indexOf("&lt;span style"));
after = body.slice(body.indexOf("&quot;&gt"), body.length -1);
body = before + after;
}
console.log(body);*/
return body;
.declareMethod("remove_css", function(body){
var regEx,
result;
regEx = new RegExp('<style.*/>');
do {
result = regEx.exec(body);
body_before = body.slice(0, result.index);
body_after = body.slice(result.index+result[0].length+1);
body = body_before+body_after;
} while (result !== null);
regEx = new RegExp('(<span style=.*>|&lt;span style.*&quot;&gt)');
do {
result = regEx.exec(body);
body_before = body.slice(0, result.index);
body_after = body.slice(result.index+result[0].length+1);
body = body_before+'<span>'+body_after;
} while (result !== null);
})
.declareMethod("is_already_parsed", function(storage, title){
return storage.all_loaded_docs()
.push(function (result){
......@@ -79,5 +88,5 @@
return false;
})
});
}(window, RSVP, rJS, jIO));
\ No newline at end of file
}(window, RSVP, rJS, jIO));
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