@@ -38,6 +38,7 @@ parser.addArgument("class"); // Add a class to the injected content.
38
38
parser . addArgument ( "history" , "none" , [ "none" , "record" ] ) ;
39
39
parser . addArgument ( "push-marker" ) ;
40
40
parser . addArgument ( "scroll" ) ;
41
+ parser . addArgument ( "remove-tags" , "script" , [ ] , true ) ;
41
42
42
43
// Note: this should not be here but the parser would bail on unknown
43
44
// parameters and expand/collapsible need to pass the url to us.
@@ -824,8 +825,8 @@ const inject = {
824
825
return true ;
825
826
} ,
826
827
827
- _sourcesFromHtml ( html , url , sources ) {
828
- const $html = this . _parseRawHtml ( html , url ) ;
828
+ _sourcesFromHtml ( html , url , sources , cfg ) {
829
+ const $html = this . _parseRawHtml ( html , url , cfg ) ;
829
830
return sources . map ( ( source ) => {
830
831
if ( source === "body" ) {
831
832
source = "#__original_body" ;
@@ -963,17 +964,21 @@ const inject = {
963
964
return page . innerHTML . trim ( ) ;
964
965
} ,
965
966
966
- _parseRawHtml ( html , url = "" ) {
967
+ _parseRawHtml ( html , url = "" , cfg = { } ) {
967
968
// remove script tags and head and replace body by a div
968
969
const title = html . match ( / \< t i t l e \> ( .* ) \< \/ t i t l e \> / ) ;
969
970
let clean_html = html
970
- . replace ( / < s c r i p t \b [ ^ < ] * (?: (? ! < \/ s c r i p t > ) < [ ^ < ] * ) * < \/ s c r i p t > / gi, "" )
971
971
. replace ( / < h e a d \b [ ^ < ] * (?: (? ! < \/ s c r i p t > ) < [ ^ < ] * ) * < \/ h e a d > / gi, "" )
972
972
. replace ( / < h t m l ( [ ^ > ] * ?) > / gi, "" )
973
973
. replace ( / < \/ h t m l ( [ ^ > ] * ?) > / gi, "" )
974
974
. replace ( / < b o d y ( [ ^ > ] * ?) > / gi, '<div id="__original_body">' )
975
975
. replace ( / < \/ b o d y ( [ ^ > ] * ?) > / gi, "</div>" ) ;
976
976
977
+ for ( const tag of cfg . removeTags || [ ] ) {
978
+ const re = RegExp ( String . raw `<${ tag } \b[^<]*(?:(?!<\/${ tag } >)<[^<]*)*<\/${ tag } >` , "gi" )
979
+ clean_html = clean_html . replace ( re , "" ) ;
980
+ }
981
+
977
982
if ( title && title . length == 2 ) {
978
983
clean_html = title [ 0 ] + clean_html ;
979
984
}
@@ -1114,7 +1119,7 @@ const inject = {
1114
1119
sources ( cfgs , data ) {
1115
1120
const sources = cfgs . map ( ( cfg ) => cfg . source ) ;
1116
1121
sources . push ( "title" ) ;
1117
- const result = this . _sourcesFromHtml ( data , cfgs [ 0 ] . url , sources ) ;
1122
+ const result = this . _sourcesFromHtml ( data , cfgs [ 0 ] . url , sources , cfgs [ 0 ] ) ;
1118
1123
return result ;
1119
1124
} ,
1120
1125
} ,
0 commit comments