Skip to content

Instantly share code, notes, and snippets.

@Kielan
Last active August 14, 2025 18:54
Show Gist options
  • Select an option

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

Select an option

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

Revisions

  1. Kielan revised this gist Aug 14, 2025. 1 changed file with 14 additions and 0 deletions.
    14 changes: 14 additions & 0 deletions LSPRustTestModuleRelationShipsDoc.rs
    Original 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)
    }
  2. 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)
    }

    }