From 885f89c78c53b2a4e5c37be86c08acfee0ca7585 Mon Sep 17 00:00:00 2001 From: drry Date: Fri, 18 Apr 2008 11:10:46 +0000 Subject: lang/javascript/vimperator-plugins/trunk/direct_bookmark.js: * `parseHTML()` * removed a `strip_tags`. now you can add a tailing slash suffix instead. git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@9713 d0d07461-0603-4401-acd4-de1884942a52 --- direct_bookmark.js | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/direct_bookmark.js b/direct_bookmark.js index ed82f7b..eebcf5d 100644 --- a/direct_bookmark.js +++ b/direct_bookmark.js @@ -135,22 +135,25 @@ } // copied from Pagerization (c) id:ofk - function parseHTML(str, strip_tags, ignore_tags){ - var exp = '^[\\s\\S]*?]*)?>|[\\S\\s]*$'; - if (strip_tags) { - strip_tags = strip_tags instanceof Array && strip_tags.length > 1 - ? '(?:' + strip_tags.join('|') + ')' - : String(strip_tags); - exp += '|<' + strip_tags + '(?:\\s[^>]*)?>|'; - } + function parseHTML(str, ignore_tags){ + var exp = "^[\\s\\S]*?]*)?>|[\\S\\s]*$"; if (ignore_tags) { if (!(ignore_tags instanceof Array)) ignore_tags = [ignore_tags]; - exp += '|' + ignore_tags.map(function(tag) { - return '<' + tag + '(?:\\s[^>]*)?>.*?'; - }).join('|'); + ignore_tags = ignore_tags.filter(function(tag) { + if (tag[tag.length - 1] != "/") return true; + tag = tag.replace(/\/$/, ""); + exp += "|" + "<" + tag + "(?:\\s[^>]*)?>.*?"; + return false; + }); + if (ignore_tags.length > 0) { + ignore_tags = ignore_tags.length > 1 + ? "(?:" + ignore_tags.join("|") + ")" + : String(ignore_tags); + exp += "|<" + ignore_tags + "(?:\\s[^>]*)?>|"; + } } - str = str.replace(new RegExp(exp, 'ig'), ''); - var res = document.implementation.createDocument(null, 'html', null); + str = str.replace(new RegExp(exp, "ig"), ""); + var res = document.implementation.createDocument(null, "html", null); var range = document.createRange(); range.setStartAfter(window.content.document.body); res.documentElement.appendChild(res.importNode(range.createContextualFragment(str), true)); @@ -266,7 +269,7 @@ xhr.open("GET","http://b.hatena.ne.jp/my",false); xhr.send(null); - var mypage_html = parseHTML(xhr.responseText, ['img', 'script']); + var mypage_html = parseHTML(xhr.responseText, ['img', 'script/']); var tags = getElementsByXPath("//ul[@id=\"taglist\"]/li/a",mypage_html); tags.forEach(function(tag){ @@ -341,7 +344,7 @@ xhr.open("GET","http://clip.livedoor.com/clip/add?link=http://example.example/",false); xhr.send(null); - var mypage_html = parseHTML(xhr.responseText, ['img', 'script']); + var mypage_html = parseHTML(xhr.responseText, ['img', 'script/']); var tags = getElementsByXPath("id(\"tag_list\")/span",mypage_html); tags.forEach(function(tag){ -- cgit v1.2.3