Skip to content

Commit 73cf61b

Browse files
committed
decode HTML entities manually.
1 parent 03a34a3 commit 73cf61b

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

lib/article.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
"use strict";
1717

18-
var read = require('./reader');
18+
var entities = require('entities'),
19+
read = require('./reader');
1920

2021
module.exports = Article;
2122

@@ -92,20 +93,23 @@ Article.prototype.getTitle = function() {
9293
if(!title){
9394
return '';
9495
}
96+
97+
title = entities.decode(title);
98+
9599
// split title by separators.
96-
var betterTitle = '', subTitles = title.split(/[\|\-_«»]/g), betterTitleExist = function(t){
100+
var betterTitle = '', subTitles = title.split(/[\|\-_«»]/g), betterTitleExist = function(t){
97101
return (t && t.length >= 10);
98102
};
103+
99104
// when find better title, break the loop.
100105
subTitles.forEach(function(t){
101106
if(betterTitleExist(betterTitle)){
102107
return false;
103-
}else{
104-
betterTitle += ' ';
105108
}
109+
console.log(betterTitle);
106110
t = t.trim();
107111
if(t){
108-
betterTitle += t;
112+
betterTitle += ' ' + t;
109113
}
110114
});
111115

@@ -135,6 +139,7 @@ Article.prototype.contentWithTEXT = function(node, output){
135139
if(output.stripSpaces){
136140
text = text.replace(/([\s\r\t\n]+)/g, ' ');
137141
}
142+
text = entities.decode(text);
138143
return text;
139144
};
140145
/**
@@ -151,6 +156,7 @@ Article.prototype.contentWithHTML = function(node, output){
151156
if(output.stripSpaces){
152157
html = html.replace(/([\r\t\n]+)/g, ' ');
153158
}
159+
html = entities.decode(html);
154160
return html;
155161
};
156162
/**
@@ -187,7 +193,7 @@ Article.prototype.contentWithJSON = function(node, dataType){
187193
//find text.
188194
var text = self.contentWithTEXT(child, dataType);
189195
if(text){
190-
retVal.push({type: 'text', value: text});
196+
retVal.push({type: 'text', value: entities.decode(text)});
191197
}
192198
}
193199
});

0 commit comments

Comments
 (0)