File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change 1
1
/* eslint-disable */
2
-
3
2
// https://github.com/yangsibai/node-html-excerpt
4
3
// const excerpt = require('html-excerpt');
4
+
5
+ const sanitizeHtml = require ( 'sanitize-html' ) ;
5
6
const trunc = require ( 'trunc-html' ) ;
6
7
8
+ const sanitizeOptions = {
9
+ allowedTags : [ 'br' ]
10
+ } ;
11
+
7
12
module . exports = function ( options = { } ) { // eslint-disable-line no-unused-vars
8
13
return function ( hook ) {
9
14
@@ -15,9 +20,8 @@ module.exports = function (options = {}) { // eslint-disable-line no-unused-vars
15
20
16
21
try {
17
22
/* eslint no-use-before-define: 0 */ // --> OFF
18
- const content = hook . data [ options . field ]
19
- . replace ( / \< b r \> | \< \/ b r \> | \< \/ b r \> | \< b r \> | \< b r \\ \> | \< p \> | \< \/ p \> / ig, "\n" )
20
- . replace ( / \< ( s t r o n g | b | i | b l o c k q u o t e | p r e | e m | u | h [ 1 - 6 ] | a ) > | \< \/ ( s t r o n g | b | i | b l o c k q u o t e | p r e | e m | u | h [ 1 - 6 ] | a ) > / ig, '' )
23
+ const content = sanitizeHtml ( hook . data [ options . field ] , sanitizeOptions )
24
+ . replace ( / \< b r \> | \< \/ b r \> | \< \/ b r \> | \< b r \> | \< b r \\ \> / ig, "\n" )
21
25
. replace ( / \< p \> \< b r \> \< \/ p \> / ig, ' ' )
22
26
. replace ( / ( \ ) { 2 , } / ig, ' ' )
23
27
. trim ( ) ;
You can’t perform that action at this time.
0 commit comments