Skip to content

Conversation

@alexbainter
Copy link
Collaborator

Closes #159.

Adds keyword highlighting for JSON schema keywords to Highlight.js's built-in JSON language. Highlight.js themes already generally color "keywords" differently from "attributes," so we just needed to add a new "mode" to Highlight.js's JSON language definition to recognize JSON schema keywords and apply the "keyword" class to them instead of "attribute."

In this case, we're actually replacing the JSON language definition with our new JSON schema-aware one, but theoretically we could add it as an additional language instead (though in my limited testing, Highlight.js was auto-selecting the original JSON definition instead of our new one, so we'd need to sort that out).

image

@alexbainter alexbainter requested a review from lisad January 6, 2026 21:16
@alexbainter
Copy link
Collaborator Author

alexbainter commented Jan 6, 2026

PS, Highlight.js is not interested in accepting new contributions, though they do offer to optionally host repositories under their highlightjs GitHub organization: https://highlightjs.readthedocs.io/en/latest/language-contribution.html. I'm not sure this is quite ready for use by others due to the issue I mentioned where Highlight.js was still automatically selecting the regular JSON highlighter even when given a JSON schema file. We could certainly look into that some more and then package this up for others.

Copy link
Member

@lisad lisad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems by far the most efficient approach - if we were going to spend more work on it it might be worth sharing, but this is something anybody else could just copy.

@alexbainter alexbainter merged commit 3462148 into main Jan 6, 2026
8 checks passed
@alexbainter alexbainter deleted the alex-159-json-schema-highlight branch January 6, 2026 22:53
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

Successfully merging this pull request may close these issues.

Estimate improving JSON Schema highlighting improvements - possibly as a contribution to OS package

2 participants