@@ -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.
@@ -823,8 +824,8 @@ const inject = {
823
824
return true ;
824
825
} ,
825
826
826
- _sourcesFromHtml ( html , url , sources ) {
827
- const $html = this . _parseRawHtml ( html , url ) ;
827
+ _sourcesFromHtml ( html , url , sources , cfg ) {
828
+ const $html = this . _parseRawHtml ( html , url , cfg ) ;
828
829
return sources . map ( ( source ) => {
829
830
if ( source === "body" ) {
830
831
source = "#__original_body" ;
@@ -962,17 +963,21 @@ const inject = {
962
963
return page . innerHTML . trim ( ) ;
963
964
} ,
964
965
965
- _parseRawHtml ( html , url = "" ) {
966
+ _parseRawHtml ( html , url = "" , cfg = { } ) {
966
967
// remove script tags and head and replace body by a div
967
968
const title = html . match ( / \< t i t l e \> ( .* ) \< \/ t i t l e \> / ) ;
968
969
let clean_html = html
969
- . replace ( / < s c r i p t \b [ ^ < ] * (?: (? ! < \/ s c r i p t > ) < [ ^ < ] * ) * < \/ s c r i p t > / gi, "" )
970
970
. replace ( / < h e a d \b [ ^ < ] * (?: (? ! < \/ s c r i p t > ) < [ ^ < ] * ) * < \/ h e a d > / gi, "" )
971
971
. replace ( / < h t m l ( [ ^ > ] * ?) > / gi, "" )
972
972
. replace ( / < \/ h t m l ( [ ^ > ] * ?) > / gi, "" )
973
973
. replace ( / < b o d y ( [ ^ > ] * ?) > / gi, '<div id="__original_body">' )
974
974
. replace ( / < \/ b o d y ( [ ^ > ] * ?) > / gi, "</div>" ) ;
975
975
976
+ for ( const tag of cfg . removeTags || [ ] ) {
977
+ const re = RegExp ( String . raw `<${ tag } \b[^<]*(?:(?!<\/${ tag } >)<[^<]*)*<\/${ tag } >` , "gi" )
978
+ clean_html = clean_html . replace ( re , "" ) ;
979
+ }
980
+
976
981
if ( title && title . length == 2 ) {
977
982
clean_html = title [ 0 ] + clean_html ;
978
983
}
@@ -1113,7 +1118,7 @@ const inject = {
1113
1118
sources ( cfgs , data ) {
1114
1119
const sources = cfgs . map ( ( cfg ) => cfg . source ) ;
1115
1120
sources . push ( "title" ) ;
1116
- const result = this . _sourcesFromHtml ( data , cfgs [ 0 ] . url , sources ) ;
1121
+ const result = this . _sourcesFromHtml ( data , cfgs [ 0 ] . url , sources , cfgs [ 0 ] ) ;
1117
1122
return result ;
1118
1123
} ,
1119
1124
} ,
0 commit comments