diff --git a/src/parser.pegjs b/src/parser.pegjs index 5d0324df9cf9c8b4fbb7d4eca03c197f34e81929..fd9889cda94de948bcf2f2eaa7d341fac2d3261b 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