cue-lang / cue

The home of the CUE language! Validate and define text-based and dynamic configuration
https://cuelang.org
Apache License 2.0
5.06k stars 288 forks source link

x/tools: HighlightJS support #1332

Open myitcv opened 2 years ago

myitcv commented 2 years ago

A few times folks (mainly on Slack) have mentioned that it would be nice for https://highlightjs.org/ to have CUE support.

Creating this as a tracking issue for coordination/discussion on that topic.

verdverm commented 2 years ago

Passing by to also suggest Pygments, which also feeds into Chroma (the highlighter used by Hugo)

https://github.com/alecthomas/chroma#more-detail

iirc, there are 3 main formats that would provide coverage across most highlighters and IDEs

jpadams commented 2 years ago

Working on getting something working right now. If anyone wants to pair, let me know. I've asked for some assistance in the Highlight.js Discord as well: https://discord.com/channels/810874741370912799/828016175735767070/968290243528757369

jpadams commented 2 years ago

Hi all! I'm on the Dagger team, and of course we love CUE ❤️

I've got a simple hightlight.js syntax highlighter working. 🥳 I'd like to ship it and then the broader CUE community can improve it over time. I'd like to host it under github.com/highlightjs/highlightjs-cue for reasons outlined below.

Today you can self-host a language syntax repo or have highlightjs host the repo under their GitHub org. They're not adding new languages to their core anymore, so you can't just merge the cue.js into src/languages. https://github.com/highlightjs/highlight.js/blob/main/extra/3RD_PARTY_QUICK_START.md

Examples of folks hosting under highlightjs:

I spoke with a Discord engineer who suggested that having the repo hosted under `highlightjs is the best move for getting it adopted by Discord.

Let me know if there is any reason that I shouldn't proceed with this plan. Thank you!

myitcv commented 2 years ago

Hi @jpadams! Thanks for investigating and raising for discussion.

I've got a simple hightlight.js syntax highlighter working

Is there somewhere we can take a look?

The reason I ask is, could the HighlightJS support be automatically generated from the EBNF in the spec?

Before the fork I was in the process of adding a test to verify the EBNF in the spec. That would be relatively easy to revitalise. Building tooling around generating different outputs from that EBNF would then be straightforward using https://pkg.go.dev/golang.org/x/exp/ebnf.

If we could generate HighlightJS and indeed other syntax representations from the EBNF, then my question is if the target repository lives outside of https://github.com/cue-lang, how do we ensure that changes/fixes are made upstream, i.e. in the CUE repository where the spec and tooling lives?

By way of an analogy, on new versions of CUE, GoReleaser currently pushes updates to https://github.com/cue-lang/homebrew-tap. The fact that that repository lives in https://github.com/cue-lang is not significant in this case, because it could live elsewhere and the source of truth would still be https://github.com/cue-lang/cue. The important detail is that the CUE repository is the source of truth.

cc @mvdan and @rogpeppe for any thoughts too.