A @mentions plugin?


I’m thinking about writing a plugin that converts @username to e.g. <a class="mention" href="..../users/username">@username</a>.

Do you know if there are currently any plugins or extensions I can have a look at, to find out how to write a plugin? (I haven’t been able to find any.)

There is not already a mentions plugin for CommonMark somewhere?

Do you know about any guidelines or tutorials anywhere about how to write plugins and extensions?

Are you interested in a @mentions plugin? I’m thinking it could be useful in combination with At.js.

(Here the Discourse team has written a @mentions plugin for Discourse’s Markdown parser: https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/dialects/mention_dialect.js (Discourse is the name of the forum software in use on this forum))

Best regards, KajMagnus


@jgm and the other core developers said that they are still ironing out the core specs and implantations before they would touch on spec extensions.

In terms of pluggability, have you considered Remarkable - high speed pluggable implementation for javascript ? Perhaps that would be easier for you to add non standard extensions via that method. They are more willing to experiment if I last remembered correctly.

Others: http://www.reddit.com/r/LightWeightMarkup/wiki/commonmark/implementations

Anyhow, it doesn’t sound too bad to detect, sounds like a simple regex capture and replace should do the trick.

1 Like

Remarkable looks like a good alternative, thanks. I just posted a question about how to write a plugin: https://github.com/jonschlinkert/remarkable/issues/58

@mention seems about as straightforward a syntax as #tag at first and it has been implemented several times, e.g. here in Discourse (as OP already mentioned) or at Stack Exchange. Remember, though, that this extension may conflict with established practice, hence expectations, elsewhere:

In code documentation and discussion, the at-sign usually introduces attribute @att or parameter @param names. In Java-Doc and relatives it precedes the “line classifier” (or whatever it is called), e.g. * @param {Number} start.

In Pandoc and probably other extensions, the at-sign is used to prefix the cite key of proper scientific citations. It usually appears inside square brackets, but also outside or without any.

Established practice in plain text environments is what should guide and limit Markdown extensions, but not every extension needs to work flawlessly in every context.

In pandoc, @foo is used for two things: references to numbered example list items and citations. Unfortunately this syntax was established before the current “mentions” convention took hold.

@mofosyne @KajMagnus Remarkable is more or less dead (no commits of note since Dec 2014). All the devs have since continued at https://github.com/markdown-it/markdown-it

A mentions plugin for it already exists over at https://www.npmjs.com/package/markdown-it-flowdock including dozens more https://www.npmjs.com/browse/keyword/markdown-it-plugin

@aleemb I’m using markdown-it since a while ago. Here is the mentions plugin I’m using in my project:


I wonder if mentions plugins tend to be app specific. They refer to users via username or ids, and the way they do this (html attribute names and format, and url links to about-user pages) might app specific I would think. Perhaps each web app will have its own mentions plugin (perhaps some base version + a few tweaks).