Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for mentions with . in the username #418

Closed
akhilacubrio opened this issue Dec 19, 2022 · 1 comment
Closed

Support for mentions with . in the username #418

akhilacubrio opened this issue Dec 19, 2022 · 1 comment
Labels

Comments

@akhilacubrio
Copy link

E.g. @dani.winks @ellie.unicorn.klein

@nfrasser
Copy link
Owner

nfrasser commented Jan 3, 2023

Hi @akhilacubrio, I have issues both for (#175) and against (#245) this behaviour. I'm going to err on leaving it as is (no mentions with .) to match allowed GitHub and Twitter mentions.

As a workaround, you can add mentions with dots yourself with a custom plugin (using the existing mention plugin as a reference):

import { createTokenClass, registerPlugin } from 'linkifyjs';

const MentionToken = createTokenClass('mention', {
	isLink: true,
	toHref() {
		return '/' + this.toString().slice(1);
	}
});

registerPlugin('mention', ({ scanner, parser }) => {
	const { DOT, HYPHEN, SLASH, UNDERSCORE, AT } = scanner.tokens;
	const { domain } = scanner.tokens.groups;

	// @
	const At = parser.start.tt(AT); // @

	// Begin with hyphen (not mention unless contains other characters)
	const AtHyphen = At.tt(HYPHEN);
	AtHyphen.tt(HYPHEN, AtHyphen);

	// Valid mention (not made up entirely of symbols)
	const Mention = At.tt(UNDERSCORE, MentionToken);

	At.ta(domain, Mention);
	AtHyphen.tt(UNDERSCORE, Mention);
	AtHyphen.ta(domain, Mention);

	// More valid mentions
	Mention.ta(domain, Mention);
	Mention.tt(HYPHEN, Mention);
	Mention.tt(UNDERSCORE, Mention);

	// Mention with a divider
	const MentionDivider = Mention.tt(SLASH);

	// Once we get a word token, mentions can start up again
	MentionDivider.ta(domain, Mention);
	MentionDivider.tt(UNDERSCORE, Mention);
	MentionDivider.tt(HYPHEN, Mention);

	// ADDED: . transitions
	const MentionDot = Mention.tt(DOT);
	MentionDot.ta(domain, Mention);
	MentionDot.tt(HYPHEN, Mention);
	MentionDot.tt(UNDERSCORE, Mention);

})

@nfrasser nfrasser closed this as not planned Won't fix, can't repro, duplicate, stale Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants