diff options
author | drry | 2008-04-18 10:49:36 +0000 |
---|---|---|
committer | drry | 2008-04-18 10:49:36 +0000 |
commit | e14eba2e1d8cbd3524cca10ec0e08de0d8c6a7f8 (patch) | |
tree | 821b01888ba098fa43b51e08585e85c082f9d9a2 | |
parent | 5f6c1488adf36fd5dd8ce461db6d1ff7e0481cf9 (diff) | |
download | vimperator-plugins-e14eba2e1d8cbd3524cca10ec0e08de0d8c6a7f8.tar.bz2 |
lang/javascript/vimperator-plugins/trunk/direct_bookmark.js:
* added `strip_tags` to `parseHTML()`.
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@9709 d0d07461-0603-4401-acd4-de1884942a52
-rw-r--r-- | direct_bookmark.js | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/direct_bookmark.js b/direct_bookmark.js index 6dff12f..ed82f7b 100644 --- a/direct_bookmark.js +++ b/direct_bookmark.js @@ -135,14 +135,21 @@ }
// copied from Pagerization (c) id:ofk
- function parseHTML(str, ignore_tags){
- str = str.replace(/^[\s\S]*?<html(?:\s[^>]+?)?>|<\/html\s*>[\S\s]*$/ig, '');
+ function parseHTML(str, strip_tags, ignore_tags){
+ var exp = '^[\\s\\S]*?<html(?:\\s[^>]*)?>|</html\\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[^>]*)?>|</' + strip_tags + '\\s*>';
+ }
if (ignore_tags) {
- ignore_tags = ignore_tags instanceof Array && ignore_tags.length > 1
- ? '(?:' + ignore_tags.join('|') + ')'
- : String(ignore_tags);
- str = str.replace(new RegExp('<' + ignore_tags + '(?:\\s[^>]+)?>|</' + ignore_tags + '\\s*>', 'ig'), '');
+ if (!(ignore_tags instanceof Array)) ignore_tags = [ignore_tags];
+ exp += '|' + ignore_tags.map(function(tag) {
+ return '<' + tag + '(?:\\s[^>]*)?>.*?</' + tag + '\\s*>';
+ }).join('|');
}
+ 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);
|