2016-12-29 07:49:51 +09:00
|
|
|
/**
|
|
|
|
|
* Mention
|
|
|
|
|
*/
|
2018-04-02 13:44:32 +09:00
|
|
|
import parseAcct from '../../../acct/parse';
|
2016-12-29 07:49:51 +09:00
|
|
|
|
2018-06-17 19:55:39 +09:00
|
|
|
export type TextElementMention = {
|
|
|
|
|
type: "mention"
|
|
|
|
|
content: string
|
|
|
|
|
username: string
|
|
|
|
|
host: string
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default function(text: string) {
|
2018-04-09 01:10:04 +09:00
|
|
|
const match = text.match(/^@[a-z0-9_]+(?:@[a-z0-9\.\-]+[a-z0-9])?/i);
|
2017-02-11 02:32:00 +09:00
|
|
|
if (!match) return null;
|
|
|
|
|
const mention = match[0];
|
2018-03-27 16:51:12 +09:00
|
|
|
const { username, host } = parseAcct(mention.substr(1));
|
2017-02-11 02:32:00 +09:00
|
|
|
return {
|
|
|
|
|
type: 'mention',
|
|
|
|
|
content: mention,
|
2018-03-27 16:51:12 +09:00
|
|
|
username,
|
|
|
|
|
host
|
2018-06-17 19:55:39 +09:00
|
|
|
} as TextElementMention;
|
|
|
|
|
}
|