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

Custom language definition for syntax highlighter #749

Closed
1 task done
danielvaughn opened this issue Sep 23, 2023 · 5 comments
Closed
1 task done

Custom language definition for syntax highlighter #749

danielvaughn opened this issue Sep 23, 2023 · 5 comments

Comments

@danielvaughn
Copy link

What version of starlight are you using?

0.10.0

What is your idea?

As a user, I would like to provide my own language definition for syntax highlighting.

Why is this feature necessary?

I admit this is an edge case - I'm developing a language and would like to provide syntax highlighting for it in my code examples. It would prevent me from having to implement a component from scratch for syntax highlighting.

(side note - I love Starlight, much thanks to the team for building this amazing tool)

Do you have examples of this feature in other projects?

  • No similar tool exists (to my knowledge)

Participation

  • I am willing to submit a pull request for this issue.
@HiDeoo
Copy link
Member

HiDeoo commented Sep 23, 2023

There is an ongoing effort to add Expressive Code to Starlight which would use astro-expressive-code to render code blocks.

I think it uses @expressive-code/plugin-shiki to perform syntax highlighting using shiki which does support adding your own language (using TextMate grammar files).

Altho, I don't know how accessible this skiki API is through Expressive Code but maybe @hippotastic may have more informations regarding that part.

@danielvaughn
Copy link
Author

fantastic, thanks so much for the quick response!

@hippotastic
Copy link
Contributor

The loadLanguage API is not accessible through plugin-shiki yet, but I can definitely add this.

Once you have a .tmLanguage file and code snippet in your language ready, please share a link to it here and we'll give it a try!

@danielvaughn
Copy link
Author

Thank you! If it's a matter of making a change to the codebase itself, I don't mind making my own PR.

@delucis
Copy link
Member

delucis commented Sep 29, 2023

Thanks for the issue and discussion! Sounds like this would need to be addressed in upstream libraries rather than Starlight directly, so will close the issue here if that’s OK — we can always revisit later if it turns out there’s some work needed on our end to expose new API options to users.

@delucis delucis closed this as completed Sep 29, 2023
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

4 participants