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 fallback Html panel support for markdown rendering #522

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.slack.sgp.intellij.ui
import com.intellij.openapi.Disposable
import com.intellij.openapi.application.runReadAction
import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.project.DumbAware
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Disposer
Expand All @@ -26,6 +27,12 @@ import com.intellij.testFramework.LightVirtualFile
import com.intellij.ui.content.ContentFactory
import com.intellij.ui.content.ContentManagerEvent
import com.intellij.ui.content.ContentManagerListener
import com.intellij.ui.dsl.builder.panel
import com.intellij.ui.dsl.gridLayout.HorizontalAlign
import com.intellij.ui.dsl.gridLayout.VerticalAlign
import com.intellij.ui.jcef.JBCefApp
import com.intellij.util.ui.HtmlPanel
import com.intellij.util.ui.JBUI
import com.slack.sgp.intellij.ChangelogJournal
import com.slack.sgp.intellij.ChangelogParser
import java.awt.BorderLayout
Expand Down Expand Up @@ -71,6 +78,8 @@ class WhatsNewPanelFactory : DumbAware {
parentDisposable: Disposable
) {

private val logger = logger<WhatsNewPanelContent>()

// Actual panel box for "What's New in Slack!"
val contentPanel: JPanel =
JPanel().apply {
Expand All @@ -91,15 +100,49 @@ class WhatsNewPanelFactory : DumbAware {

val file = LightVirtualFile("changelog.md", changeLogContent.changeLogString ?: "")

val panel = MarkdownJCEFHtmlPanel(project, file)
Disposer.register(parentDisposable, panel)

val html = runReadAction {
MarkdownUtil.generateMarkdownHtml(file, changeLogContent.changeLogString ?: "", project)
}

panel.setHtml(html, 0)
return panel.component
// We have to support two different modes here: the modern JCEF-based one and the legacy
// Legacy is because Android Studio ships with a broken markdown plugin that doesn't work with
// JCEF
// https://issuetracker.google.com/issues/159933628#comment19
val panel =
if (JBCefApp.isSupported()) {
logger.debug("Using JCEFHtmlPanelProvider")
MarkdownJCEFHtmlPanel(project, file)
.apply {
Disposer.register(parentDisposable, this)
setHtml(html, 0)
}
.component
} else {
logger.debug("Using HtmlPanel")
val htmlPanel =
object : HtmlPanel() {
init {
isVisible = true
// Padding
border = JBUI.Borders.empty(16)
update()
}

override fun getBody(): String {
return html
}
}
panel {
row {
cell(htmlPanel)
.horizontalAlign(HorizontalAlign.FILL)
.verticalAlign(VerticalAlign.FILL)
}
.resizableRow()
}
}

return panel
}
}
}
Loading