<commit_before>// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.github.ui.util

import com.intellij.ide.ui.laf.darcula.DarculaUIUtil
import com.intellij.openapi.util.NlsSafe
import com.intellij.ui.ColorUtil
import com.intellij.ui.Graphics2DDelegate
import com.intellij.util.ui.JBUI
import com.intellij.util.ui.codereview.BaseHtmlEditorPane
import org.jetbrains.plugins.github.GithubIcons
import java.awt.*
import java.awt.image.ImageObserver
import javax.swing.text.Element
import javax.swing.text.FlowView
import javax.swing.text.ParagraphView
import javax.swing.text.View
import javax.swing.text.html.BlockView
import javax.swing.text.html.ImageView
import javax.swing.text.html.StyleSheet

internal class HtmlEditorPane() : BaseHtmlEditorPane(GithubIcons::class.java) {
  constructor(@NlsSafe body: String) : this() {
    setBody(body)
  }

  override fun createViewFactory(iconsClass: Class<*>) = GHViewFactory()

  protected class GHViewFactory : BaseHtmlEditorPane.HtmlEditorViewFactory(GithubIcons::class.java) {
    override fun create(elem: Element): View {
      val view = super.create(elem)
      if (view is ImageView) {
        return MyScalingImageView(elem)
      }
      if (elem.name == "blockquote") {
        return GitHubQuoteView(elem)
      }
      if (view is ParagraphView) {
        return GHParagraphView(elem)
      }
      return view
    }
  }

  private class GitHubQuoteView(element: Element) : BlockView(element, Y_AXIS) {

    override fun setPropertiesFromAttributes() {
      super.setPropertiesFromAttributes()
      setInsets(topInset, 0, bottomInset, rightInset)
    }

    override fun getStyleSheet(): StyleSheet = super.getStyleSheet().apply {
      val borderWidth = JBUI.scale(2)
      val borderColor = ColorUtil.toHex(DarculaUIUtil.getOutlineColor(true, false))
      val padding = JBUI.scale(10)
      //language=CSS
      addRule("""
        html body blockquote p {
          border-left: ${borderWidth}px solid ${borderColor};
          padding-left: ${padding}px;
        }
      """.trimIndent())
    }<commit_msg>[github] do not adjust CSS on the fly<commit_after>// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.github.ui.util

import com.intellij.ide.ui.laf.darcula.DarculaUIUtil
import com.intellij.openapi.util.NlsSafe
import com.intellij.ui.ColorUtil
import com.intellij.ui.Graphics2DDelegate
import com.intellij.util.ui.JBUI
import com.intellij.util.ui.codereview.BaseHtmlEditorPane
import org.jetbrains.plugins.github.GithubIcons
import java.awt.*
import java.awt.image.ImageObserver
import javax.swing.text.Element
import javax.swing.text.FlowView
import javax.swing.text.ParagraphView
import javax.swing.text.View
import javax.swing.text.html.BlockView
import javax.swing.text.html.ImageView

internal class HtmlEditorPane() : BaseHtmlEditorPane(GithubIcons::class.java) {
  constructor(@NlsSafe body: String) : this() {
    setBody(body)
  }

  override fun createViewFactory(iconsClass: Class<*>) = GHViewFactory()

  protected class GHViewFactory : BaseHtmlEditorPane.HtmlEditorViewFactory(GithubIcons::class.java) {
    override fun create(elem: Element): View {
      val view = super.create(elem)
      if (view is ImageView) {
        return MyScalingImageView(elem)
      }
      if (elem.name == "blockquote") {
        return GHQuoteView(elem)
      }
      if (view is ParagraphView) {
        return GHParagraphView(elem)
      }
      return view
    }
  }

  private class GHQuoteView(element: Element) : BlockView(element, Y_AXIS) {

    init {
      val borderWidth = JBUI.scale(2)
      val borderColor = ColorUtil.toHex(DarculaUIUtil.getOutlineColor(true, false))
      val padding = JBUI.scale(10)
      //language=CSS
      styleSheet.addRule("""
        html body blockquote p {
          border-left: ${borderWidth}px solid ${borderColor};
          padding-left: ${padding}px;
        }
      """.trimIndent())
    }

    override fun setPropertiesFromAttributes() {
      super.setPropertiesFromAttributes()
      setInsets(topInset, 0, bottomInset, rightInset)
    }
{'fraction_non_alphanumeric': 0.10169885966953689, 'fraction_numerical': 0.006981615080288574, 'mean_word_length': 3.621505376344086, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2499150', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1321, 'n_words': 293}