-
Notifications
You must be signed in to change notification settings - Fork 45
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
Add API to syntax-highlight code #386
Comments
Hi @francisconoriega! Hope you don't mind me jumping in, I was looking at the issue recently and gotten a couple thoughts. Editor scheme in the IDE allows specifying different colors for the same token for different languages. For example, set orange for keywords in Java and blue in Kotlin. Implementors might also want to highlight identifiers (even more so, different identifiers with different colors), underline syntax errors and so on. It would be nice if Jewel API could reflect all that. Which means highlighter should also be a composition local, because all this extravaganza might be a bit too much for standalone. Something like this: public interface MarkdownCodeHighligher {
public /* suspend? */ fun highlight(code: String, mimeType: MimeType /* , codeBlock: MarkdownBlock.Code.Fenced */): AnnotatedString
} i.e. pretty much how it's described in the issue 😄 It gives a lot of flexibility to implementors, and leaves room for optimizations. Like, cache lexer/parser result using And I think foundation should be kept as simple as possible. Probably there shouldn't be any highlighting logic (and an additional dependency that comes with it) at all. A 3rd party library is worth using in standalone version, whereas in bridge we could just use IntelliJ SDK. |
Another note — I think syntax highlighting is not necessarily something we want to tie exclusively to the Markdown renderer. I can see the need for it elsewhere too |
hmm all fair points. @rock3r do you want to go with a different approach (ie I should stop work on the current PR), or do feel okay going this way, if the comments in the PR are addressed? |
I feel like we should probably have a chat before you spend more time on this, so we are better aligned. Can jump on Slack in a few minutes? |
* Provide default no-op highlighter * Use highlighter to render code in `DefaultMarkdownBlockRenderer` * Extract `MimeType` from markdown to core
* Provide default no-op highlighter * Use highlighter to render code in `DefaultMarkdownBlockRenderer` * Extract `MimeType` from markdown to core
* Introduce code highlighting API (#386) * Provide default no-op highlighter * Use highlighter to render code in `DefaultMarkdownBlockRenderer` * Extract `MimeType` from markdown to core * Provide highlighter implementations * Use no-op in standalone * Use IJP lexer-based highlighter in IDE bridge; no-op as default * otherwise we need to pass the project around * Provide option to define own highlighter via `ProvideMarkdownStyling` * Re-highlight code when the editor scheme color changed * API dump * Inject highlighting dispatcher into the constructor * Add `ProvideMarkdownStyling` override with the project Using this override will automatically set up a highlighter, no need to do that manually. * Fail fast if file type is unknown * Background and text decoration in TextAttributes -> SpanStyle conversion * Revert MimeType looks * Simplify NoOpCodeHighlighter * Remove unnecessary color specifier
* Introduce code highlighting API (#386) * Provide default no-op highlighter * Use highlighter to render code in `DefaultMarkdownBlockRenderer` * Extract `MimeType` from markdown to core * Provide highlighter implementations * Use no-op in standalone * Use IJP lexer-based highlighter in IDE bridge; no-op as default * otherwise we need to pass the project around * Provide option to define own highlighter via `ProvideMarkdownStyling` * Re-highlight code when the editor scheme color changed * API dump * Inject highlighting dispatcher into the constructor * Add `ProvideMarkdownStyling` override with the project Using this override will automatically set up a highlighter, no need to do that manually. * Fail fast if file type is unknown * Background and text decoration in TextAttributes -> SpanStyle conversion * Revert MimeType looks * Simplify NoOpCodeHighlighter * Remove unnecessary color specifier
Users may want to display code, and having syntax highlighting is important for readability.
We need an API that can be used to turn a string of code into a highlighted AnnotatedString. On the bridge side, the styling must come from the EditorScheme, and on the standalone side, we should use the defaults for Light and Dark themes. On the bridge side, we expect fully semantic highlighting where supported by the current IDE, and on the standalone side, we expect basic syntax-based highlighting. On the bridge side, all the languages supported by the current IDE must be supported, and on the standalone side we must support at a minimum Kotlin, Java, XML, JSON, JS, TS, HTML, CSS, Python. Other languages support is nice to have but not required.
Thoughts:
JewelTheme.codeStyling
The text was updated successfully, but these errors were encountered: