A super simple library to programmatically generate text.
The scribe
package doesn't do much on its own, but provides the foundation for the other packages to build upon.
The markdown
package provides a simple way to generate markdown content programmatically.
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!**
}
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!
}
BlockQuote("text")
text
Bold("text")
text
BoldItalic("text")
text
Code("text")
text
CodeBlock("fmt.Println(\"Hello World!\")", "go")
fmt.Println("Hello World!")
Details("description", "This is a simple details block")
description
This is a simple details block
FencedBlock("This is a fenced block")
This is a fenced block
FrontMatter("yaml", "title: Hello World")
title: Hello World
Heading(4, "Sub-Heading")
HorizontalRule('-', 3)
Image("Image of a cat", "[ImageUrl]")
Italic("text")
text
Link("Link to GitHub Homepage", "https://github.com")
UnorderedList([]string{"Item 1", "Item 2", "Item 3"})
- Item 1
- Item 2
- Item 3
OrderedList([]string{"Item 1", "Item 2", "Item 3"})
- Item 1
- Item 2
- Item 3
Paragraph("This is a simple paragraph")
This is a simple paragraph
Strikethrough("text")
text
Table([]string{"Name", "Age"}, [][]string{{"John", "21"}, {"Jane", "22"}})
Name Age John 21 Jane 22
This project is licensed under the MIT License - see the LICENSE file for details