diff options
author | Peter Cai <[email protected]> | 2020-04-15 20:58:54 +0800 |
---|---|---|
committer | Peter Cai <[email protected]> | 2020-04-15 20:58:54 +0800 |
commit | 5f790e4b379abfd139e9d90d024c5d726b46af8b (patch) | |
tree | b097b1476a28298f312fcf2c2083f3909ae7f88a | |
parent | 4bf676419d10cf34d6e4dd9e9c949763b5618a42 (diff) | |
download | paprika-5f790e4b379abfd139e9d90d024c5d726b46af8b.tar.gz |
blog: make links open in new tab by default
-rw-r--r-- | src/blog.rs | 4 |
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(®ex_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(®ex_links, "<a target=\"_blank\" href=\"$1\">"); + js_html.into() } |