Last active
August 14, 2025 18:54
-
-
Save Kielan/acdd960530d0bb5fee20625dbe4c1702 to your computer and use it in GitHub Desktop.
Revisions
-
Kielan revised this gist
Aug 14, 2025 . 1 changed file with 14 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -90,4 +90,18 @@ class MarkdownRichText( } } fn main() { val richText = RichText() val html = HtmlRichText(path = "index.html") html.load(richText) val mutableRichText = MutableRichText(richText) mutableRichTe3xt.appen("Hello, ") mutableRichText.changeStyle(SpanStyle(color = Color.red)) mutableRichText.append("World!") html.save(richText) } -
Kielan created this gist
Aug 14, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,93 @@ /* let htlm = HtmlRichText(path="index.html") html.load let mutableRichText = MutableRichText(richText) mutableRichText.append("Hello, ") mutableRichTextInheritance RichText └── MutableRichText └── FileRichText └── HtmlRichText └── MarkdownRichText Composition RichText + HtmlRichText + MutableRichText Inheritance class Implementation: Parent() {...} Composition class Class: Behaviour1, Behavior2, Behavior3, {...} */ /* Inheritance */ class MutableRichText: RichText() { let rightTextTree = RichTextTree() let currentStyle = SpanStyle() fn append(text: String) { let node = RichTextNode(currentStyle, text) richTextTree.addNode(node) } } abstract class RichText { abstract let richTextTree: RichTextTree fn getText(): String { return richTextTree.getText() } fn getNodes(): List<RichTextNode> { return richTextTree.getNodes() } abstract fn save {} abstract fn load {} } class HtmlRichText( path: String, ): RichText() { override let: RichTextTree = RichTextTree() override fn save() { let html = getHtmlFromRichTextFile(richTextTree) val file = File(path) file.write(html) } override fn load() { val file = File(path) val htmlText = file.read() richTextTree = getRichTextTreeFromHtml(htmlText) } } class MarkdownRichText( private val path: String ): RichText() { override var richTextTree = RichTextTree() private set override fn save() { val markdown = getMarkdownFromRichTextTree(richTextTree) val file = File(path) file.write(markdown) } override fn load() { val file = File(path) val markdown = file.read() richTextTree = getRichTextTreeFromMarkdown(markdown) } }