Skip to content

Commit

Permalink
Unwrap links #4
Browse files Browse the repository at this point in the history
  • Loading branch information
asumaran committed Feb 1, 2016
1 parent e0a71d7 commit 2374fe3
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions lib/gimporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,32 @@ var connection = mysql.createConnection({

connection.connect();

function unwrap(childrens) {
var escapedChildrens = [];
childrens.forEach(function(el){
if (el.type === 'tag' && el.name === 'a') {
if (el.children) {
var els = unwrap(el.children);
Array.prototype.push.apply(escapedChildrens, els);
} else {
if (el.type === 'tag' && el.name === 'a') {
el.children.forEach(function(_el){
escapedChildrens.push(el);
})
} else {
escapedChildrens.push(el);
}
}
} else {
escapedChildrens.push(el);
if (el.children) {
el.children = unwrap(el.children);
}
}
});
return escapedChildrens;
}

gimporter.insertFile = function(data, tableName) {
var deferred = Q.defer();
var baseData = {
Expand Down Expand Up @@ -66,7 +92,16 @@ gimporter.getLegislacionData = function($file, file) {
$file('version').not(function(i, el){
return cmsConfigExcludes.indexOf(el.attribs.cms_config) > -1;
}).each(function (k, v) {
var $el = $file(v);

var $el = $file(v),
childrens = [];

$el.contents().each(function(i, el) {
childrens.push(el);
});

$el[0].children = unwrap(childrens);

contentBuffer.push($el.html());
contentBufferText.push($el.text());
});
Expand Down Expand Up @@ -110,7 +145,15 @@ gimporter.getJurisprudenciaData = function($file, file) {
$file('version').not(function(i, el){
return cmsConfigExcludes.indexOf(el.attribs.cms_config) > -1;
}).each(function (k, v) {
var $el = $file(v);
var $el = $file(v),
childrens = [];

$el.contents().each(function(i, el) {
childrens.push(el);
});

$el[0].children = unwrap(childrens);

contentBuffer.push($el.html());
contentBufferText.push($el.text());
});
Expand Down

0 comments on commit 2374fe3

Please sign in to comment.