From 7cfcf2edcdc4f74dbe23320c9b0e3c5e42ea18b4 Mon Sep 17 00:00:00 2001 From: marihachi <marihachi0620@gmail.com> Date: Sat, 20 Mar 2021 12:25:29 +0900 Subject: [PATCH] implement mention --- src/parser.pegjs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/parser.pegjs b/src/parser.pegjs index 5d0324d..fd9889c 100644 --- a/src/parser.pegjs +++ b/src/parser.pegjs @@ -155,6 +155,7 @@ inline / strike / inlineCode / mathInline + / mention / hashtag / url / link @@ -259,6 +260,37 @@ mathInline }); } +// inline: mention + +mention + = "@" name:mentionName host:("@" host:mentionHost { return host; })? +{ + return createNode('mention', { + name: name, + host: host + }); +} + +mentionName + = !"-" mentionNamePart+ // first char is not "-". +{ + return text(); +} + +mentionNamePart + = "-" &mentionNamePart // last char is not "-". + / [a-z0-9_]i + +mentionHost + = ![.-] mentionHostPart+ // first char is neither "." nor "-". +{ + return text(); +} + +mentionHostPart + = [.-] &mentionHostPart // last char is neither "." nor "-". + / [a-z0-9_]i + // inline: hashtag hashtag -- GitLab