Commit 3d5b9c94 authored by Alexandra Rogova's avatar Alexandra Rogova

better regex

parent 677c64a2
...@@ -58,24 +58,8 @@ ...@@ -58,24 +58,8 @@
}) })
.declareMethod("remove_css", function(body){ .declareMethod("remove_css", function(body){
var regEx, var regEx = new RegExp('(style="(.*?)"|style=&quot(.*?)&quot)', 'gi');
result; return body.replace(regEx, "");
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){ .declareMethod("is_already_parsed", function(storage, title){
......
...@@ -40,10 +40,8 @@ ...@@ -40,10 +40,8 @@
parser = new DOMParser(); parser = new DOMParser();
xmlDoc = parser.parseFromString(item.body,"text/xml"); xmlDoc = parser.parseFromString(item.body,"text/xml");
body_text = xmlDoc.getElementsByTagName("description")[0].childNodes[0].nodeValue; body_text = xmlDoc.getElementsByTagName("description")[0].childNodes[0].nodeValue;
console.log("ok : " + item.title);
return this.cut_description(body_text, key) return this.cut_description(body_text, key)
.push(function (result){ .push(function (result){
//console.log(item.title);
if (result === null) body.innerHTML = ""; if (result === null) body.innerHTML = "";
else body.innerHTML = result.slice(1); else body.innerHTML = result.slice(1);
list_item.appendChild(body); list_item.appendChild(body);
...@@ -63,8 +61,9 @@ ...@@ -63,8 +61,9 @@
.declareMethod("cut_description", function(body, key){ .declareMethod("cut_description", function(body, key){
var regEx, var regEx,
result; result;
regEx = new RegExp('[^.]*' +" " + key + " " + '[^.]*\.', 'g'); regEx = new RegExp('[^.?!]*' + ' ' + key + ' ' + '[^.?!]*[.?!]', 'gm');
result = regEx.exec(body); result = regEx.exec(body);
console.log("result:");console.log(result);
if (result === null) return null; if (result === null) return null;
else return result[0]; else return result[0];
}); });
......
...@@ -60,7 +60,6 @@ ...@@ -60,7 +60,6 @@
promise_list = [], promise_list = [],
i; i;
for (i = 0; i < gadget.state.to_load.length; i++){ for (i = 0; i < gadget.state.to_load.length; i++){
//console.log(gadget.state.parser_gadget);
promise_list.push(gadget.state.parser_gadget.read_file("./test-files/" + gadget.state.to_load[i])); promise_list.push(gadget.state.parser_gadget.read_file("./test-files/" + gadget.state.to_load[i]));
} }
RSVP.all(promise_list); RSVP.all(promise_list);
...@@ -71,7 +70,7 @@ ...@@ -71,7 +70,7 @@
options; options;
options = { options = {
query:'(title:"% '+key+' %") OR (title:"'+ key + '%") OR (body:"% '+key+' %")' query:'(title:"% '+key+' %") OR (title:"'+ key + ' %") OR (body:"% '+key+' %")'
}; };
return gadget.state.result_gadget.clear() return gadget.state.result_gadget.clear()
......
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