blog: make links open in new tab by default

This commit is contained in:
Peter Cai 2020-04-15 20:58:54 +08:00
parent 4bf676419d
commit 5f790e4b37
No known key found for this signature in database
GPG Key ID: 71F5FB4E4F3FD54F
1 changed files with 4 additions and 0 deletions

View File

@ -256,6 +256,10 @@ impl PostContentCache {
let regex_code = RegExp::new("<pre><code class=\"language-([^\"]*)\">", "ig");
let js_html = js_html.replace_by_pattern(&regex_code, "<pre><code class=\"hljs\">");
// Transform all non-self-refernece links (does not start with "#") to target="_blank"
let regex_links = RegExp::new("<a href=\"((?!#)[^\"]*)\">", "ig");
let js_html = js_html.replace_by_pattern(&regex_links, "<a target=\"_blank\" href=\"$1\">");