Skip to content

Commit 5f07404

Browse files
extract and link hashtags without trailing punctuation
1 parent c0add7d commit 5f07404

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

backend/data/blooms.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from data.connection import db_cursor
77
from data.users import User
88

9+
import re
10+
911

1012
@dataclass
1113
class Bloom:
@@ -16,7 +18,7 @@ class Bloom:
1618

1719

1820
def add_bloom(*, sender: User, content: str) -> Bloom:
19-
hashtags = [word[1:] for word in content.split(" ") if word.startswith("#")]
21+
hashtags = re.findall(r"#(\w+)", content)
2022

2123
now = datetime.datetime.now(tz=datetime.UTC)
2224
bloom_id = int(now.timestamp() * 1000000)

front-end/components/bloom.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ const createBloom = (template, bloom) => {
3737
function _formatHashtags(text) {
3838
if (!text) return text;
3939
return text.replace(
40-
/\B#[^#]+/g,
41-
(match) => `<a href="/hashtag/${match.slice(1)}">${match}</a>`
40+
/#([\p{L}0-9_]+)/gu,
41+
(_, tag) => `<a href="/hashtag/${encodeURIComponent(tag)}">#${tag}</a>`
4242
);
4343
}
4444

0 commit comments

Comments
 (0)