diff --git a/src/components/account.jsx b/src/components/account.jsx
index 9230e394..90f91015 100644
--- a/src/components/account.jsx
+++ b/src/components/account.jsx
@@ -2,6 +2,7 @@ import './account.css';
import { useEffect, useState } from 'preact/hooks';
+import enhanceContent from '../utils/enhance-content';
import shortenNumber from '../utils/shorten-number';
import store from '../utils/store';
@@ -122,7 +123,12 @@ export default ({ account }) => {
{shortenNumber(statusesCount)} Posts
diff --git a/src/utils/enhance-content.js b/src/utils/enhance-content.js
index 2eeeaa57..af3e8f6d 100644
--- a/src/utils/enhance-content.js
+++ b/src/utils/enhance-content.js
@@ -1,16 +1,24 @@
import emojifyText from './emojify-text';
-export default (content, { emojis }) => {
- // 1. Emojis
+export default (content, opts = {}) => {
+ const { emojis } = opts;
let enhancedContent = content;
+ const dom = document.createElement('div');
+ dom.innerHTML = enhancedContent;
+ // 1. Emojis
if (emojis) {
enhancedContent = emojifyText(enhancedContent, emojis);
}
- // 2. Code blocks
- const dom = document.createElement('div');
- dom.innerHTML = enhancedContent;
+ // 2. Add target="_blank" to all links with no target="_blank"
+ // E.g. `note` in `account`
+ const links = Array.from(dom.querySelectorAll('a:not([target="_blank"])'));
+ links.forEach((link) => {
+ link.setAttribute('target', '_blank');
+ });
+
+ // 3. Code blocks
// Check for with markdown-like content "```"
const blocks = Array.from(dom.querySelectorAll('p')).filter((p) =>
/^```[^]+```$/g.test(p.innerText.trim()),
@@ -28,7 +36,7 @@ export default (content, { emojis }) => {
pre.appendChild(code);
block.replaceWith(pre);
});
- enhancedContent = dom.innerHTML;
+ enhancedContent = dom.innerHTML;
return enhancedContent;
};