Skip to content

Instantly share code, notes, and snippets.

@Kielan
Created August 14, 2025 18:50
Show Gist options
  • Select an option

  • Save Kielan/aecc9476b5ef398c27dd377a4c714726 to your computer and use it in GitHub Desktop.

Select an option

Save Kielan/aecc9476b5ef398c27dd377a4c714726 to your computer and use it in GitHub Desktop.

Revisions

  1. Kielan created this gist Aug 14, 2025.
    93 changes: 93 additions & 0 deletions LSPRustTestModuleRelationShipsDoc.rs
    Original 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)
    }

    }