JavaScriptのみで記述されたブログツール・ソフトウェアです。表示にExt JSを使用します
Revision | 2088df019c1c2a699fc64d68ecc9eca955fc2532 (tree) |
---|---|
Time | 2009-06-04 00:25:49 |
Author | NARUSE, Yui <naruse@user...> |
Commiter | NARUSE, Yui |
Optimize replacing anchors.
@@ -157,15 +157,12 @@ function validateText(contents){ | ||
157 | 157 | } |
158 | 158 | |
159 | 159 | // Aタグを変換する |
160 | - while (target_tag = contents.match(/<a[^>]*>/)) { | |
161 | - // href="..."の部分のみを抜き出す | |
162 | - target_element = target_tag[0].match(/href=["'][^"']*["']/i); | |
160 | + var base_uri = document.location.href.replace(/[^\/]+$/, ''); | |
161 | + var func = function(target, quote, url) { | |
163 | 162 | // 相対URIが検出された場合、フルに置換する |
164 | - target_element = target_element[0].replace(/\.\//, "http://lunardial.sakura.ne.jp/"); | |
165 | - // Aタグ全体を消去し、再度Aクローズタグの置換を行う | |
166 | - contents = contents.replace(target_tag, ""); | |
167 | - contents = contents.replace(/<\/a>/i, " ( " + target_element.replace(/href=|["']/g, "") + " ) "); | |
168 | - } | |
163 | + return '( ' + url.replace(/^(?!http)(?:\.\/)?/, base_uri) + ' )'; | |
164 | + }; | |
165 | + contents = contents.replace(/<a[^>]*href=(["'])(.*?)\1[^>]*>.*?<\/a>/i, func); | |
169 | 166 | |
170 | 167 | // 通常のタグすべてを削除する |
171 | 168 | contents = contents.replace(/<[^>]*>|<\/[^>]*>/ig, ""); |