@@ -38,6 +38,7 @@ parser.addArgument("class"); // Add a class to the injected content.
3838parser . addArgument ( "history" , "none" , [ "none" , "record" ] ) ;
3939parser . addArgument ( "push-marker" ) ;
4040parser . addArgument ( "scroll" ) ;
41+ parser . addArgument ( "remove-tags" , "script" , [ ] , true ) ;
4142
4243// Note: this should not be here but the parser would bail on unknown
4344// parameters and expand/collapsible need to pass the url to us.
@@ -832,8 +833,8 @@ const inject = {
832833 return true ;
833834 } ,
834835
835- _sourcesFromHtml ( html , url , sources ) {
836- const $html = this . _parseRawHtml ( html , url ) ;
836+ _sourcesFromHtml ( html , url , sources , cfg ) {
837+ const $html = this . _parseRawHtml ( html , url , cfg ) ;
837838 return sources . map ( ( source ) => {
838839 if ( source === "body" ) {
839840 source = "#__original_body" ;
@@ -971,17 +972,21 @@ const inject = {
971972 return page . innerHTML . trim ( ) ;
972973 } ,
973974
974- _parseRawHtml ( html , url = "" ) {
975+ _parseRawHtml ( html , url = "" , cfg = { } ) {
975976 // remove script tags and head and replace body by a div
976977 const title = html . match ( / \< t i t l e \> ( .* ) \< \/ t i t l e \> / ) ;
977978 let clean_html = html
978- . replace ( / < s c r i p t \b [ ^ < ] * (?: (? ! < \/ s c r i p t > ) < [ ^ < ] * ) * < \/ s c r i p t > / gi, "" )
979979 . replace ( / < h e a d \b [ ^ < ] * (?: (? ! < \/ s c r i p t > ) < [ ^ < ] * ) * < \/ h e a d > / gi, "" )
980980 . replace ( / < h t m l ( [ ^ > ] * ?) > / gi, "" )
981981 . replace ( / < \/ h t m l ( [ ^ > ] * ?) > / gi, "" )
982982 . replace ( / < b o d y ( [ ^ > ] * ?) > / gi, '<div id="__original_body">' )
983983 . replace ( / < \/ b o d y ( [ ^ > ] * ?) > / gi, "</div>" ) ;
984984
985+ for ( const tag of cfg . removeTags || [ ] ) {
986+ const re = RegExp ( String . raw `<${ tag } \b[^<]*(?:(?!<\/${ tag } >)<[^<]*)*<\/${ tag } >` , "gi" )
987+ clean_html = clean_html . replace ( re , "" ) ;
988+ }
989+
985990 if ( title && title . length == 2 ) {
986991 clean_html = title [ 0 ] + clean_html ;
987992 }
@@ -1122,7 +1127,7 @@ const inject = {
11221127 sources ( cfgs , data ) {
11231128 const sources = cfgs . map ( ( cfg ) => cfg . source ) ;
11241129 sources . push ( "title" ) ;
1125- const result = this . _sourcesFromHtml ( data , cfgs [ 0 ] . url , sources ) ;
1130+ const result = this . _sourcesFromHtml ( data , cfgs [ 0 ] . url , sources , cfgs [ 0 ] ) ;
11261131 return result ;
11271132 } ,
11281133 } ,
0 commit comments