@@ -17,109 +17,55 @@ import javax.swing.text.html.HTMLEditorKit
1717
1818/* *
1919 * Markdown rendering component that hides the concrete rendering strategy
20- * (HTML, StyledDocument, etc.) behind a uniform API.
20+ * behind a uniform API. Create instances via [MdView.html] .
2121 *
22- * Callers interact only with markdown source text and semantic events —
23- * never with underlying widget types.
24- *
25- * Create instances via [MdView.html].
2622 * All public methods must be called on the EDT.
2723 */
2824abstract class MdView private constructor() {
2925
30- /* * The Swing component to embed in layouts. */
3126 abstract val component: JComponent
32-
33- /* * Replace the entire content with new markdown source. */
3427 abstract fun set (text : String )
35-
36- /* * Append a streaming delta to the current content. */
3728 abstract fun append (delta : String )
38-
39- /* * Reset to empty. */
4029 abstract fun clear ()
41-
4230 abstract fun addLinkListener (listener : LinkListener )
43-
4431 abstract fun removeLinkListener (listener : LinkListener )
4532
46- // -- styling ----------------------------------------------------------
47-
48- /* * Body text font family and size. */
4933 abstract var font: Font
50-
51- /* * Body text foreground color. */
5234 abstract var foreground: Color
53-
54- /* * Overall background color. */
5535 abstract var background: Color
56-
57- /* * Link foreground color. */
5836 abstract var linkColor: Color
59-
60- /* * Inline code background color. */
6137 abstract var codeBg: Color
62-
63- /* * Code block (pre) background color. */
6438 abstract var preBg: Color
65-
66- /* * Code block (pre) foreground color. */
6739 abstract var preFg: Color
68-
69- /* * Code / pre font family. */
7040 abstract var codeFont: String
71-
72- /* * Blockquote left-border and text color. */
7341 abstract var quoteBorder: Color
7442 abstract var quoteFg: Color
75-
76- /* * Table / th / td border color. */
7743 abstract var tableBorder: Color
7844
7945 /* *
80- * Whether the component paints its own background.
81- * When `false`, the body background CSS is omitted and the underlying
82- * Swing component is set to non-opaque so the parent's background
83- * shows through.
46+ * When `false`, body background CSS is omitted and the Swing component
47+ * is set to non-opaque so the parent's background shows through.
8448 */
8549 abstract var opaque: Boolean
8650
87- /* *
88- * Semantic event fired when a user clicks a link inside rendered markdown.
89- */
9051 data class LinkEvent (
9152 val href : String ,
9253 val point : Point ? = null ,
9354 )
9455
95- /* *
96- * Callback for link activations inside a [MdView].
97- */
9856 fun interface LinkListener {
9957 fun onLink (event : LinkEvent )
10058 }
10159
102- // -- test helpers (package-visible) ------------------------------------
103-
104- /* * Returns the current raw markdown source. */
10560 internal abstract fun markdown (): String
106-
107- /* * Returns the rendered HTML body (not Swing-rewritten). */
10861 internal abstract fun html (): String
109-
110- /* * Returns the full wrapped HTML including CSS. */
11162 internal abstract fun styledHtml (): String
112-
113- /* * Fire a synthetic link activation for testing. */
11463 internal abstract fun simulateLink (href : String )
11564
11665 companion object {
117- /* * Create a [MdView] backed by commonmark-java → HTML → JEditorPane. */
11866 fun html (): MdView = HtmlImpl ()
11967 }
12068
121- // -- private HTML implementation ---------------------------------------
122-
12369 private class HtmlImpl : MdView () {
12470
12571 private val listeners = mutableListOf<LinkListener >()
@@ -163,8 +109,6 @@ abstract class MdView private constructor() {
163109 }
164110 }
165111
166- // -- style fields with defaults -----------------------------------
167-
168112 override var font: Font = JBUI .Fonts .label()
169113 set(value) { field = value; markDirty() }
170114
@@ -240,9 +184,7 @@ abstract class MdView private constructor() {
240184 }
241185
242186 override fun markdown (): String = source.toString()
243-
244187 override fun html (): String = rendered
245-
246188 override fun styledHtml (): String = wrapped
247189
248190 override fun simulateLink (href : String ) {
0 commit comments