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

Add syntax highlighting to markdown preview #592

Conversation

AlexVanGogen
Copy link
Collaborator

I decided to go with the Flow in highlighter API so that implementations might be able to react to their internal alterations of a color scheme and provide new styled strings accordingly. Another approach that was in my mind is highlight returning a single AnnotatedString and a separate flow in the API acting as a trigger to re-highlight the code. It would make implementations of highlight simpler but at the cost of leaking into the foundation (and not every implementation would need that). If you know how it can be done better with compose, please tell, I'm still new to this and would love to learn good practices :)

For standalone, there are no working highlighters beside no-op one that just wraps a string without applying any styles.

Indented code blocks aren't supported as well, mainly because they aren't supported in JCEF 🙂 but also because it requires using some language guesser (and it seems a point for a futher discussion).

@rock3r rock3r self-requested a review September 10, 2024 21:45
@rock3r rock3r added the feature New feature or request label Sep 10, 2024
@rock3r rock3r linked an issue Sep 10, 2024 that may be closed by this pull request
@rock3r rock3r linked an issue Sep 10, 2024 that may be closed by this pull request
* Provide default no-op highlighter
* Use highlighter to render code in `DefaultMarkdownBlockRenderer`
* Extract `MimeType` from markdown to core
* 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`
Using this override will automatically set up a highlighter,
no need to do that manually.
@AlexVanGogen AlexVanGogen force-pushed the alexvangogen/markdown-preview-syntax-highlighting branch from 7a914b8 to 7d83b61 Compare September 20, 2024 08:03
Copy link
Collaborator

@rock3r rock3r left a comment

Choose a reason for hiding this comment

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

Great job! Let's ship this :)

@rock3r rock3r merged commit 6716c92 into JetBrains:main Sep 23, 2024
1 check passed
rock3r pushed a commit that referenced this pull request Sep 24, 2024
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add API to syntax-highlight code
3 participants