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

Markdown syntax highlighting in IDE doesn't work for languages that don't have a parser, should fallback to TextMate grammars #741

Open
vsiva opened this issue Jan 9, 2025 · 0 comments
Labels
markdown This issue impacts the Markdown rendering subsystem

Comments

@vsiva
Copy link

vsiva commented Jan 9, 2025

When you have a markdown fenced code block, with say Python code, and you try to render this inside IntelliJ IDEA, it won't show any syntax highlighting. This is because the LexerBasedCodeHighlighter has:

  override fun highlight(code: String, mimeType: MimeType): Flow<AnnotatedString> {
        val language = mimeType.toLanguageOrNull() ?: return flowOf(AnnotatedString(code))

Here, language is null if there's no plugin providing a valid Language.

IntelliJ packages TextMate grammars which are used by the editor in such a case. This code should probably look something like:

    val existingLanguage = mimeType.toLanguageOrNull()

    // Fall back on textmate if no language was found
    val language =
      existingLanguage
        ?: LanguageUtil.findRegisteredLanguage("textmate")
        ?: return flowOf(AnnotatedString(code))

    val fileExtension =
      if (existingLanguage == null) {
        // When using textmate, we have to determine the file extension ourselves from the MimeType
        mimeType.toFileExtension()
      } else {
        language.associatedFileType?.defaultExtension ?: return flowOf(AnnotatedString(code))
      }
@rock3r rock3r added the markdown This issue impacts the Markdown rendering subsystem label Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
markdown This issue impacts the Markdown rendering subsystem
Projects
None yet
Development

No branches or pull requests

2 participants