highlightjs / highlightjs/highlight.js

Discuss: (js/ts) JSX/TSX support roll-up thread

Open
#2,998 2 comments 14 reactions 1 assignee Claimed by @joshgoebel View on GitHub
bug discuss/propose help welcome language
Dominant language
JavaScript
Stars
25k
Forks
3.8k
Avg merge
11h 35m
Merged PRs (30d)
3

Description

This is a high-level thread created to track the overall discussion of our JSX/TSX support.

- https://github.com/highlightjs/highlight.js/issues/1625 (comment highlighting)
- https://github.com/highlightjs/highlight.js/issues/2324 (inline code)
- https://github.com/highlightjs/highlight.js/issues/2721 (JSX inside inline code, ad infinitum)

Support for JSX/TSX is not a single thing. We already include "basic" support for embedded XML/HTML fragments using the `xml` sublanguage. We do not support comments or embedded JS.

_This has all been attempted several times and is a very, very hard problem._ **It may actually be impossible for us to solve for various reasons.**

1. Technical: we simply may not have the necessary tools in our parsing engine. We have very limited tools for man again state since our desire is to AVOID state as much as possible.
2. Philosophical: even if we have the tools we **purposely** do not build full grammar parsers (out of scope), we only do smart pattern matching.
3. Philosophical: (again) we must highlight incomplete/incorrect code snippets to the best of our ability - we must highlight partial code as well as code out of context. A full context-aware parser creates issues here also.

Any solution here needs to be simple enough to maintain long term and not violate our core philosophy. Right now our limited support is *fairly* simple (all things considered). I'm open to being shown this is a much easier problem than I imagine it to be.

This thread exists to talk about the high level problem/approach instead of the individual mini-problems. Or perhaps the whole discussion will move here since many of these items are intermingled and hard to handle in isolation.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.