[MFM] Improve various parsing

Resolve #2779
Resolve #3053
This commit is contained in:
syuilo
2018-11-16 21:57:19 +09:00
parent e3b8495431
commit 0ff390ed80
7 changed files with 79 additions and 46 deletions

View File

@@ -12,9 +12,10 @@ export type TextElementMention = {
host: string;
};
export default function(text: string) {
export default function(text: string, before: string) {
const match = text.match(/^@[a-z0-9_]+(?:@[a-z0-9\.\-]+[a-z0-9])?/i);
if (!match) return null;
if (/[a-zA-Z0-9]$/.test(before)) return null;
const mention = match[0];
const { username, host } = parseAcct(mention.substr(1));
const canonical = host != null ? `@${username}@${toUnicode(host)}` : mention;