8000 [v2] Match tokens via named capturing groups · Issue #3924 · PrismJS/prism · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[v2] Match tokens via named capturing groups #3924

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

Open
LeaVerou opened this issue May 1, 2025 · 0 comments
Open

[v2] Match tokens via named capturing groups #3924

LeaVerou opened this issue May 1, 2025 · 0 comments

Comments

@LeaVerou
Copy link
Member
LeaVerou commented May 1, 2025

Prism's token syntax is helpful for certain things, but for other use cases a single regex with named capturing groups can be easier.
I propose we just use all named capturing groups as token names (automatically converted to kebab-case)
If that becomes a problem, we can introduce a setting to ignore some of them.

This can be combined with regular tokens, they'd just operate on the unmatched text. The tokens matched in the regex can also be specified again in the literal if we want to specify inside or $language. E.g. imagine something like this for the markdown code blocks:

'code-block': {
	pattern: /^```(?<codeLanguage>[a-z-]+).+(?:\n|\r\n?)(?<code>[\s\S]*)?(?:\n|\r\n?)```$/i,
	'punctuation': /```/,
	'code': {
		$language: groups => groups.codeLanguage,
	}
}

Note that this means inside can also be a regex now.

Here's a more substantial example: 586bd55

@LeaVerou LeaVerou added v2 and removed v2 labels May 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0