const regex = /^(\w[\w.-]{0,59})\b/i; function applyMentions(state, silent, isSpace, isPunctChar, mentionLookup, getURL) { let pos = state.pos; // 64 = @ if (silent || state.src.charCodeAt(pos) !== 64) { return false; } if (pos > 0) { let prev = state.src.charCodeAt(pos-1); if (!isSpace(prev) && !isPunctChar(String.fromCharCode(prev))) { return false; } } // skip if in a link if (state.tokens) { let last = state.tokens[state.tokens.length-1]; if (last) { if (last.type === 'link_open') { return false; } if (last.type === 'html_inline' && last.content.substr(0,2) === " { md.inline.ruler.push('mentions', (state,silent)=> applyMentions( state, silent, md.utils.isSpace, md.utils.isPunctChar, md.options.discourse.mentionLookup, md.options.discourse.getURL )); }); }