Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getTextContent: function (element) {
var isPre = (element.name === 'pre');
var out = this.walkTreeForText1(element, isPre)
if(out !== undefined){
out = out.replace(/[ ]+/g, ' '); // remove double spaces
out = out.replace(/\r /g, '\r'); // remove any space direcly after a line return
out = out.replace(/\r{3,}/g, '\r\r'); // remove anything more than double line return
return this.trim(entities.decode(out,2)) // decode HTML entities
}else{
return undefined
}
},
parse: function(dom, node, textFormat){
var out;
this.textFormat = (textFormat)? textFormat : this.textFormat;
if(this.textFormat === 'normalised'){
out = this.walkTreeForText( dom, node );
if(out !== undefined){
out = out.replace( / /g, ' ') ; // exchanges html entity for space into space char
out = utils.removeWhiteSpace( out ); // removes linefeeds, tabs and addtional spaces
out = entities.decode( out, 2 ); // decode HTML entities
out = out.replace( '–', '-' ); // correct dash decoding
return utils.trim( out );
}else{
return undefined;
}
}else{
return this.textContent( dom(node).html(), this.textFormat );
}
},
child,
text;
if(this.excludeTags.indexOf(element.name) > -1){
return out;
}
if(element.name === 'br'){
return '\r';
}
// if element is a text node get its text
if(element.type && element.type === 'text'){
var textItem = this.getEltText(element)
if(this.trim(textItem) !== '') {
textItem = entities.decode(textItem,2)
if(isPre){
out = textItem.replace(/ /g, ' ');
}else{
out = this.trim( this.removeWhiteSpace(textItem), ' ', ' ');
}
}
}
// get the text of the child nodes
if(element.children && element.children.length > 0){
for (var j = 0; j < element.children.length; j++) {
child = element.children[j];
if(child.name === 'pre'){
isPre = true;
res.on('end', function () {
var pos, pos2, title;
pos = data.indexOf('<title>');
if (pos !== -1) {
pos2 = data.indexOf('</title>', pos);
if (pos2 !== -1) {
title = data.substr(pos + 7, pos2 - (pos + 7));
// decode HTML entities
title = entities.decode(title, 2);
callback(title);
} else {
callback(false);
}
} else {
callback(false);
}
});
}).on('error', function (err) {
var getSnippet = function(str) {
return Entities.decode(stripHtml(str)).trim();
}
const series: Array = Object.keys(json.categories).map(catKey => {
const cat = json.categories[catKey];
return {
url: cat.slug,
name: cat.name,
description: cat.description,
commissionedLength: getSeriesCommissionedLength(cat.slug),
color: getSeriesColor(cat.slug)
};
});
const article: Article = {
contentType: contentType,
url: url,
headline: entities.decode(json.title),
standfirst: entities.decode(standfirst),
description: entities.decode(json.excerpt),
datePublished: new Date(json.date),
mainMedia: mainMedia,
thumbnail: thumbnail,
articleBody: articleBody,
associatedMedia: mainImage ? [mainImage] : [],
author: List(),
bodyParts: bodyParts,
series: series,
positionInSeries: positionInSeries
};
return article;
}
}
utils.getSnippet = function(str) {
return entities.decode(utils.stripHtml(str)).trim();
}
getEValue: function(dom, node) {
return entities.decode(dom(node).html(), 2);
//return dom(node).html();
},
exports.decode = function(str) { return entities.decode(str, 2); };
const series: Array = Object.keys(json.categories).map(catKey => {
const cat = json.categories[catKey];
return {
url: cat.slug,
name: cat.name,
description: cat.description,
commissionedLength: getSeriesCommissionedLength(cat.slug),
color: getSeriesColor(cat.slug)
};
});
const article: Article = {
contentType: contentType,
url: url,
headline: entities.decode(json.title),
standfirst: entities.decode(standfirst),
description: entities.decode(json.excerpt),
datePublished: new Date(json.date),
mainMedia: mainMedia,
thumbnail: thumbnail,
articleBody: articleBody,
associatedMedia: mainImage ? [mainImage] : [],
author: List(),
bodyParts: bodyParts,
series: series,
positionInSeries: positionInSeries
};
return article;
}
}