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

Conversation

ZacSweers
Copy link
Collaborator

@ZacSweers ZacSweers commented Aug 10, 2023

Android Studio frustratingly ships with a broken version of the embedded markdown plugin, which prevents use of the modern JCEF API we were using. This adds a fallback implementation for when that's not available and just uses a simpler html panel. Code blocks don't work and it's a little plain, but it's otherwise ok.

Screenshot 2023-08-10 at 12 56 05 AM

Android Studio frustratingly ships with a broken version of the embedded markdown plugin, which prevents use of the modern JCEF API we were using. This adds a fallback implementation for when that's not available and just uses a simpler html panel.
@github-actions
Copy link

Review:

  1. Remove unused imports: Remove the unused imports at the top of the file to improve code readability.
import com.intellij.openapi.diagnostic.logger
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
  1. Extract the creation of the panel into a separate method: Extract the creation of the panel into a separate method to improve code readability and maintainability. This method can be called createPanel and it should take the project, file, and html as parameters and return the created panel.
private fun createPanel(project: Project, file: VirtualFile, html: String): JComponent {
    // Create the panel here
}
  1. Use the extracted method in the main method: Replace the existing code for creating the panel with a call to the extracted method.
val panel = createPanel(project, file, html)
return panel
  1. Simplify the panel creation for the legacy mode: In the legacy mode, instead of using the panel DSL, you can directly create an HtmlPanel and set its body to the generated HTML.
val htmlPanel = HtmlPanel().apply {
    isVisible = true
    border = JBUI.Borders.empty(16)
    setBody(html)
}
return htmlPanel
  1. Remove unnecessary logging: Remove the logging statements that are not necessary for the functionality of the code.
// Remove these lines
private val logger = logger<WhatsNewPanelContent>()
logger.debug("Using JCEFHtmlPanelProvider")
logger.debug("Using HtmlPanel")

By following these steps, the code can be improved for readability and maintainability.

@ZacSweers ZacSweers added this pull request to the merge queue Aug 10, 2023
Merged via the queue into main with commit 891922d Aug 10, 2023
3 checks passed
@ZacSweers ZacSweers deleted the z/panelHtml branch August 10, 2023 05:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants