@@ -15,15 +15,53 @@ object MarkdownViewer {
15
15
jEditorPane.setContentType(" text/html" )
16
16
val htmlEditorKit = HTMLEditorKitBuilder ().build()
17
17
18
- // val backgroundColor = UIUtil.getPanelBackground()
19
- //
20
- // val editorFontName = EditorColorsManager.getInstance().schemeForCurrentUITheme.editorFontName
21
- // val editorFontSize = EditorColorsManager.getInstance().schemeForCurrentUITheme.editorFontSize
22
- // val fontFamilyAndSize = "font-family:'" + editorFontName + "'; font-size:" + editorFontSize + "pt;"
18
+ val backgroundColor = UIUtil .getPanelBackground()
19
+ val backgroundColorHex = ColorUtil .toHex(backgroundColor)
23
20
24
- htmlEditorKit.getStyleSheet().addRule(" code { background-color: #fff; }" )
25
- htmlEditorKit.getStyleSheet().addRule(" p { margin-top: 1px }" )
21
+ val editorFontName = EditorColorsManager .getInstance().schemeForCurrentUITheme.editorFontName
22
+ val editorFontSize = EditorColorsManager .getInstance().schemeForCurrentUITheme.editorFontSize
23
+ val fontFamilyAndSize = " font-family:'" + editorFontName + " '; font-size:" + editorFontSize + " pt;"
26
24
25
+ val cssRules = """
26
+ body { $fontFamilyAndSize margin: 8px; line-height: 1.5; }
27
+ p { margin-top: 0.8em; margin-bottom: 0.8em; }
28
+
29
+ /* Headings */
30
+ h1 { font-size: 1.6em; margin-top: 1em; margin-bottom: 0.6em; font-weight: bold; }
31
+ h2 { font-size: 1.4em; margin-top: 0.9em; margin-bottom: 0.5em; font-weight: bold; }
32
+ h3 { font-size: 1.2em; margin-top: 0.8em; margin-bottom: 0.4em; font-weight: bold; }
33
+ h4, h5, h6 { font-size: 1.1em; margin-top: 0.7em; margin-bottom: 0.3em; font-weight: bold; }
34
+
35
+ /* Code blocks */
36
+ pre { background-color: #f5f5f5; border-radius: 4px; padding: 8px; overflow-x: auto; margin: 1em 0; }
37
+ code { font-family: 'JetBrains Mono', Consolas, monospace; background-color: #f5f5f5; padding: 2px 4px; border-radius: 3px; font-size: 0.9em; }
38
+
39
+ /* Lists */
40
+ ul, ol { margin-top: 0.5em; margin-bottom: 0.5em; padding-left: 2em; }
41
+ li { margin: 0.3em 0; }
42
+
43
+ /* Blockquotes */
44
+ blockquote { border-left: 4px solid #ddd; padding-left: 1em; margin-left: 0; margin-right: 0; color: #777; }
45
+
46
+ /* Tables */
47
+ table { border-collapse: collapse; width: 100%; margin: 1em 0; }
48
+ th, td { border: 1px solid #ddd; padding: 6px; text-align: left; }
49
+ th { background-color: #f2f2f2; }
50
+
51
+ /* Links */
52
+ a { color: #2196F3; text-decoration: none; }
53
+ a:hover { text-decoration: underline; }
54
+
55
+ /* Horizontal rule */
56
+ hr { border: 0; height: 1px; background-color: #ddd; margin: 1em 0; }
57
+
58
+ /* Inline elements */
59
+ strong, b { font-weight: bold; }
60
+ em, i { font-style: italic; }
61
+ """ .trimIndent()
62
+
63
+ htmlEditorKit.styleSheet.addRule(cssRules)
64
+
27
65
jEditorPane.also {
28
66
it.editorKit = htmlEditorKit
29
67
it.isEditable = false
@@ -45,5 +83,4 @@ object MarkdownViewer {
45
83
jEditorPane.addHyperlinkListener(BrowserHyperlinkListener .INSTANCE );
46
84
return jEditorPane
47
85
}
48
-
49
- }
86
+ }
0 commit comments