-
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 syntax highlighting to markdown preview #592
Merged
rock3r
merged 11 commits into
JetBrains:main
from
AlexVanGogen:alexvangogen/markdown-preview-syntax-highlighting
Sep 23, 2024
Merged
Add syntax highlighting to markdown preview #592
rock3r
merged 11 commits into
JetBrains:main
from
AlexVanGogen:alexvangogen/markdown-preview-syntax-highlighting
Sep 23, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rock3r
reviewed
Sep 10, 2024
foundation/src/main/kotlin/org/jetbrains/jewel/foundation/code/MimeType.kt
Outdated
Show resolved
Hide resolved
...tion/src/main/kotlin/org/jetbrains/jewel/foundation/code/highlighting/NoOpCodeHighlighter.kt
Outdated
Show resolved
Hide resolved
...ge/src/main/kotlin/org/jetbrains/jewel/bridge/code/highlighting/LexerBasedCodeHighlighter.kt
Outdated
Show resolved
Hide resolved
...ge/src/main/kotlin/org/jetbrains/jewel/bridge/code/highlighting/LexerBasedCodeHighlighter.kt
Outdated
Show resolved
Hide resolved
...ge/src/main/kotlin/org/jetbrains/jewel/bridge/code/highlighting/LexerBasedCodeHighlighter.kt
Show resolved
Hide resolved
...les/ide-plugin/src/main/kotlin/org/jetbrains/jewel/samples/ideplugin/ComponentShowcaseTab.kt
Outdated
Show resolved
Hide resolved
...ng/src/main/kotlin/org/jetbrains/jewel/intui/markdown/bridge/BridgeProvideMarkdownStyling.kt
Show resolved
Hide resolved
.../core/src/main/kotlin/org/jetbrains/jewel/markdown/rendering/DefaultMarkdownBlockRenderer.kt
Outdated
Show resolved
Hide resolved
* 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
force-pushed
the
alexvangogen/markdown-preview-syntax-highlighting
branch
from
September 20, 2024 08:03
7a914b8
to
7d83b61
Compare
.../core/src/main/kotlin/org/jetbrains/jewel/markdown/rendering/DefaultMarkdownBlockRenderer.kt
Show resolved
Hide resolved
rock3r
approved these changes
Sep 23, 2024
There was a problem hiding this 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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 ishighlight
returning a singleAnnotatedString
and a separate flow in the API acting as a trigger to re-highlight
the code. It would make implementations ofhighlight
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).