Shresht7 / Scribe

A library to programmatically generate text such as markdown πŸ“

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Scribe

A super simple library to programmatically generate text.


πŸ“¦ Packages

scribe

The scribe package doesn't do much on its own, but provides the foundation for the other packages to build upon.

markdown

The markdown package provides a simple way to generate markdown content programmatically.

Usage

package main

import (
    "fmt"

    "github.com/Shresht7/Scribe/markdown"
)

func main() {
    
    // Creating a Markdown document
    doc := markdown.NewDocument()
    doc.AddHeading(2, "This is a sub-heading")
    doc.AddParagraph("Hello World!")
    fmt.Println(doc)

    // Output:
    // ## This is a sub-heading
    // Hello World!

    // Alternatively, you can use the `AppendChild` method to add nodes to the document

    doc.AppendChild(
        markdown.Heading(2, "This is a sub-heading")
        markdown.Paragraph("Hello World!")
    )

    // Or, use any func directly
    fmt.Println(markdown.Bold("Hello World!")) // **Hello World!**

}

Custom Nodes

Creating custom nodes is as simple as creating a new struct that implements the Node interface.

type CustomNode struct {
    text string
}

func (c *CustomNode) String() string {
    return ">> "+c.text
}

func main() {
    doc := markdown.NewDocument()
    doc.AppendChild(&CustomNode{"Hello World!"})
    fmt.Println(doc) // >> Hello World!
}

πŸ“• Markdown API Reference

Blockquote

BlockQuote("text")

text

Bold

Bold("text")

text

BoldItalic

BoldItalic("text")

text

Code

Code("text")

text

CodeBlock

CodeBlock("fmt.Println(\"Hello World!\")", "go")
fmt.Println("Hello World!")

Details

Details("description", "This is a simple details block")
description

This is a simple details block

FencedBlock

FencedBlock("This is a fenced block")
This is a fenced block

FrontMatter

FrontMatter("yaml", "title: Hello World")
title: Hello World

Heading

Heading(4, "Sub-Heading")

Sub-Heading

HorizontalRule

HorizontalRule('-', 3)

Image

Image("Image of a cat", "[ImageUrl]")

Image of a cat

Italic

Italic("text")

text

Link

Link("Link to GitHub Homepage", "https://github.com")

Link to GitHub Homepage

List

UnorderedList([]string{"Item 1", "Item 2", "Item 3"})
  • Item 1
  • Item 2
  • Item 3
OrderedList([]string{"Item 1", "Item 2", "Item 3"})
  1. Item 1
  2. Item 2
  3. Item 3

Paragraph

Paragraph("This is a simple paragraph")

This is a simple paragraph

Strikethrough

Strikethrough("text")

text

Table

Table([]string{"Name", "Age"}, [][]string{{"John", "21"}, {"Jane", "22"}})
Name Age
John 21
Jane 22

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details

About

A library to programmatically generate text such as markdown πŸ“

License:MIT License


Languages

Language:Go 100.0%