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

Detect Notation Transformers dynamically #705

Open
4 tasks done
fuma-nama opened this issue Jun 18, 2024 · 0 comments
Open
4 tasks done

Detect Notation Transformers dynamically #705

fuma-nama opened this issue Jun 18, 2024 · 0 comments

Comments

@fuma-nama
Copy link
Contributor

Clear and concise description of the problem

Currently, Shiki uses a single regex matcher for notation transformers.
It resulted in a few problems:

  • Invalid syntax is included: JavaScript doesn't support # comment for adding comment, but notation transformers will still parse it as a normal comment.
  • Poor support of other formats: When using it with some formats, like the liquid template language, the current regex cannot match its comments.

Suggested solution

To solve the problem, we can use a specific matcher depending on the format/language, and allow people to customise it.

For example, when processing a JavaScript file, we only support JSX and JS style comments.

About the exact implementation, I think we can add a matchers map for different languages.
When cannot find a matcher for current format, it fallbacks to our current regex matcher which supports common comment syntaxes.

const matchers = {
  javascript: [/regex1/, /regex2/],
  typescript: [/regex1/, /regex2/], 
  csharp: [/regex1/],
  ...
}

People can pass their own matchers object to customise it.

Alternative

For some notation transformers, we can use the corresponding meta transformer instead. like line/word highlight have their meta transformers, but this is not supported for all notation transformers.

Additional context

No response

Validations

Contributes

  • If this feature request is accepted, I am willing to submit a PR to fix this issue
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