rss-parser
Advanced tools
Comparing version 3.8.1 to 3.9.0
@@ -41,3 +41,3 @@ const fields = module.exports = {}; | ||
'author', | ||
'content:encoded', | ||
['content:encoded', 'content:encoded', {includeSnippet: true}], | ||
'enclosure', | ||
@@ -44,0 +44,0 @@ 'dc:creator', |
@@ -6,7 +6,9 @@ const utils = module.exports = {}; | ||
utils.stripHtml = function(str) { | ||
return str.replace(/<(?:.|\n)*?>/gm, ''); | ||
str = str.replace(/([^\n])<\/?(h|br|p|ul|ol|li|blockquote|section|table|tr|div)(?:.|\n)*?>([^\n])/gm, '$1\n$3') | ||
str = str.replace(/<(?:.|\n)*?>/gm, ''); | ||
return str; | ||
} | ||
utils.getSnippet = function(str) { | ||
return entities.decode(utils.stripHtml(str)).trim(); | ||
return entities.decodeHTML(utils.stripHtml(str)).trim(); | ||
} | ||
@@ -45,3 +47,3 @@ | ||
} | ||
const { keepArray } = options; | ||
const { keepArray, includeSnippet } = options; | ||
if (xml[from] !== undefined){ | ||
@@ -53,2 +55,5 @@ dest[to] = keepArray ? xml[from] : xml[from][0]; | ||
} | ||
if (includeSnippet && dest[to] && typeof dest[to] === 'string') { | ||
dest[to + 'Snippet'] = utils.getSnippet(dest[to]); | ||
} | ||
}) | ||
@@ -55,0 +60,0 @@ } |
{ | ||
"name": "rss-parser", | ||
"version": "3.8.1", | ||
"version": "3.9.0", | ||
"main": "index.js", | ||
@@ -25,3 +25,3 @@ "types": "index.d.ts", | ||
"dependencies": { | ||
"entities": "^1.1.1", | ||
"entities": "^2.0.3", | ||
"xml2js": "^0.4.19" | ||
@@ -28,0 +28,0 @@ }, |
@@ -145,3 +145,4 @@ # rss-parser | ||
* `keepArray`: `true` to return *all* values for fields that can have multiple entries. Default: return the first item only. | ||
* `keepArray (false)` - set to `true` to return *all* values for fields that can have multiple entries. | ||
* `includeSnippet (false)` - set to `true` to add an additional field, `${toField}Snippet`, with HTML stripped out | ||
@@ -148,0 +149,0 @@ ```js |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
1811627
11654
244
+ Addedentities@2.2.0(transitive)
- Removedentities@1.1.2(transitive)
Updatedentities@^2.0.3