Created
August 14, 2025 18:50
-
-
Save Kielan/aecc9476b5ef398c27dd377a4c714726 to your computer and use it in GitHub Desktop.
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 characters
| /* | |
| 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) | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment