index : paprika

A blogging platform written in Rust for Cloudflare Workers, integrated with Standard Notes

diff options
context:
space:
mode:
authorPeter Cai <[email protected]>2020-04-15 20:58:54 +0800
committerPeter Cai <[email protected]>2020-04-15 20:58:54 +0800
commit5f790e4b379abfd139e9d90d024c5d726b46af8b (patch)
treeb097b1476a28298f312fcf2c2083f3909ae7f88a
parent4bf676419d10cf34d6e4dd9e9c949763b5618a42 (diff)
downloadpaprika-5f790e4b379abfd139e9d90d024c5d726b46af8b.tar.gz
blog: make links open in new tab by default
-rw-r--r--src/blog.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/blog.rs b/src/blog.rs
index ab66bd9..7ae4264 100644
--- a/src/blog.rs
+++ b/src/blog.rs
@@ -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\">");
+
js_html.into()
}