Changeset 9713

Show
Ignore:
Timestamp:
04/18/08 20:10:46 (5 years ago)
Author:
drry
Message:

lang/javascript/vimperator-plugins/trunk/direct_bookmark.js:

  • parseHTML()
    • removed a strip_tags. now you can add a tailing slash suffix instead.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/vimperator-plugins/trunk/direct_bookmark.js

    r9709 r9713  
    136136 
    137137    // copied from Pagerization (c) id:ofk 
    138     function parseHTML(str, strip_tags, ignore_tags){ 
    139         var exp = '^[\\s\\S]*?<html(?:\\s[^>]*)?>|</html\\s*>[\\S\\s]*$'; 
    140         if (strip_tags) { 
    141             strip_tags = strip_tags instanceof Array && strip_tags.length > 1 
    142                         ? '(?:' + strip_tags.join('|') + ')' 
    143                         : String(strip_tags); 
    144             exp += '|<' + strip_tags + '(?:\\s[^>]*)?>|</' + strip_tags + '\\s*>'; 
    145         } 
     138    function parseHTML(str, ignore_tags){ 
     139        var exp = "^[\\s\\S]*?<html(?:\\s[^>]*)?>|</html\\s*>[\\S\\s]*$"; 
    146140        if (ignore_tags) { 
    147141            if (!(ignore_tags instanceof Array)) ignore_tags = [ignore_tags]; 
    148             exp += '|' + ignore_tags.map(function(tag) { 
    149                 return '<' + tag + '(?:\\s[^>]*)?>.*?</' + tag + '\\s*>'; 
    150             }).join('|'); 
    151         } 
    152         str = str.replace(new RegExp(exp, 'ig'), ''); 
    153         var res = document.implementation.createDocument(null, 'html', null); 
     142            ignore_tags = ignore_tags.filter(function(tag) { 
     143                if (tag[tag.length - 1] != "/") return true; 
     144                tag = tag.replace(/\/$/, ""); 
     145                exp += "|" + "<" + tag + "(?:\\s[^>]*)?>.*?</" + tag + "\\s*>"; 
     146                return false; 
     147            }); 
     148            if (ignore_tags.length > 0) { 
     149                ignore_tags = ignore_tags.length > 1 
     150                            ? "(?:" + ignore_tags.join("|") + ")" 
     151                            : String(ignore_tags); 
     152                exp += "|<" + ignore_tags + "(?:\\s[^>]*)?>|</" + ignore_tags + "\\s*>"; 
     153            } 
     154        } 
     155        str = str.replace(new RegExp(exp, "ig"), ""); 
     156        var res = document.implementation.createDocument(null, "html", null); 
    154157        var range = document.createRange(); 
    155158        range.setStartAfter(window.content.document.body); 
     
    267270                xhr.send(null); 
    268271 
    269                 var mypage_html = parseHTML(xhr.responseText, ['img', 'script']); 
     272                var mypage_html = parseHTML(xhr.responseText, ['img', 'script/']); 
    270273                var tags = getElementsByXPath("//ul[@id=\"taglist\"]/li/a",mypage_html); 
    271274 
     
    342345                xhr.send(null); 
    343346 
    344                 var mypage_html = parseHTML(xhr.responseText, ['img', 'script']); 
     347                var mypage_html = parseHTML(xhr.responseText, ['img', 'script/']); 
    345348                var tags = getElementsByXPath("id(\"tag_list\")/span",mypage_html); 
    346349