Skip to content

Commit

Permalink
fix: 修复 replaceAll 兼容性问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Tokinx authored Jul 1, 2024
1 parent fee561e commit 64b5efc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions static/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -1008,21 +1008,21 @@ const $modules = new function () {
.map(text => text.replace(/\s| |>/g, ''))
.filter(item => !!item)
.forEach(topic => {
content = content.replaceAll(topic, `<span class="chip c-hand text-primary" data-topic="${topic}">${topic.replace("#", "")}</span>`);
content = content.replace(new RegExp(topic, "g"), `<span class="chip c-hand text-primary" data-topic="${topic}">${topic.replace("#", "")}</span>`);
});

// 高亮引用 /note/5841
new Set((content.match(/(\/note\/\d+)/g) || [])).forEach(quote => {
const id = quote.replace('/note/', '');
content = content.replaceAll(quote, `<a href="javascript:void(0);" class="text-primary" data-quote="${id}">~${quote}</a>`);
content = content.replace(new RegExp(quote, "g"), `<a href="javascript:void(0);" class="text-primary" data-quote="${id}">~${quote}</a>`);
});

// url转link
let url_regex = /(https?:\/\/(?:www\.|(?!www))[a-zA-Z\d][a-zA-Z\d-]+[a-zA-Z\d]\.[^\s|^<]{2,}|www\.[a-zA-Z\d][a-zA-Z\d-]+[a-zA-Z\d]\.[^\s|^<]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z\d]+\.[^\s|^<]{2,}|www\.[a-zA-Z\d]+\.[^\s|^<]{2,})/g;
let url_match = content.match(url_regex);
if ( url_match ) {
url_match.forEach(url => {
content = content.replaceAll(url, `<a href="${url}" target="_blank" class="chip text-primary tooltip" data-tooltip="${url}" style="text-decoration: none;overflow: unset"><i class="dashicons dashicons-external"></i> Link</a>`);
content = content.replace(new RegExp(url, "g"), `<a href="${url}" target="_blank" class="chip text-primary tooltip" data-tooltip="${url}" style="text-decoration: none;overflow: unset"><i class="dashicons dashicons-external"></i> Link</a>`);
});
}

Expand Down
2 changes: 1 addition & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Description: Simple, smooth, data-driven, responsive WordPress theme
Author: Tokin
Author URI: https://biji.io
Version: 0.8.3
Version: 0.8.4
Tested up to: 5.9.3
Requires at least: 5.8
Requires PHP: 7.0
Expand Down

0 comments on commit 64b5efc

Please sign in to comment.