8000 [v2] `$language` for highlighting languages embedded in other languages · Issue #3923 · PrismJS/prism · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[v2] $language for highlighting languages embedded in other languages #3923

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

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

Comments

@LeaVerou
Copy link
Member
LeaVerou commented May 1, 2025

We often have cases where languages are embedded in other languages.
The way we handle it now is variations of this (example from the coffeescript definition):

'script': {
	pattern: /[\s\S]+/,
	alias: 'language-javascript',
	inside: 'javascript',
},

This has several issues:

  1. It's not obvious that this is a language at all
  2. Clumsy, because we have to specify the language twice
  3. No obvious extension to dynamic languages

I think I'm now convinced that a $language special key is a good approach for this. The snippet above would look like this:

'script': {
	$language: 'javascript',
},

Sure, it loses some of the elegance of treating everything as just a set of tokens but the thing is, they're not the same. There are loading implications for languages that don't exist for grammars defined inline, so this needs to be explicit somehow.
Additionally, it naturally provides an extension point for dynamic languages. I'm thinking a regex group and/or a function to transform the matched value.
There could also be an $optional: boolean value.

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