https://github.com/shresht7/scribe
A library to programmatically generate text such as markdown 📝
https://github.com/shresht7/scribe
Last synced: about 2 months ago
JSON representation
A library to programmatically generate text such as markdown 📝
- Host: GitHub
- URL: https://github.com/shresht7/scribe
- Owner: Shresht7
- License: mit
- Created: 2023-02-09T17:49:14.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-02-13T08:43:43.000Z (over 2 years ago)
- Last Synced: 2025-03-06T06:15:16.090Z (over 1 year ago)
- Language: Go
- Homepage:
- Size: 73.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `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
```go
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.
```go
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`
```go
BlockQuote("text")
```
> > text
### `Bold`
```go
Bold("text")
```
> **text**
### `BoldItalic`
```go
BoldItalic("text")
```
> ***text***
### `Code`
```go
Code("text")
```
> `text`
### `CodeBlock`
```go
CodeBlock("fmt.Println(\"Hello World!\")", "go")
```
> ```go
> fmt.Println("Hello World!")
> ```
### `Details`
```go
Details("description", "This is a simple details block")
```
>
>
> description
>
> This is a simple details block
>
>
### `FencedBlock`
```go
FencedBlock("This is a fenced block")
```
> ```
> This is a fenced block
> ```
### `FrontMatter`
```go
FrontMatter("yaml", "title: Hello World")
```
> ```yaml
> title: Hello World
> ```
### `Heading`
```go
Heading(4, "Sub-Heading")
```
> #### Sub-Heading
### `HorizontalRule`
```go
HorizontalRule('-', 3)
```
> ---
### `Image`
```go
Image("Image of a cat", "[ImageUrl]")
```
> 
### `Italic`
```go
Italic("text")
```
> *text*
### `Link`
```go
Link("Link to GitHub Homepage", "https://github.com")
```
> [Link to GitHub Homepage](https://github.com)
### `List`
```go
UnorderedList([]string{"Item 1", "Item 2", "Item 3"})
```
> - Item 1
> - Item 2
> - Item 3
```go
OrderedList([]string{"Item 1", "Item 2", "Item 3"})
```
> 1. Item 1
> 2. Item 2
> 3. Item 3
### `Paragraph`
```go
Paragraph("This is a simple paragraph")
```
> This is a simple paragraph
### `Strikethrough`
```go
Strikethrough("text")
```
> ~~text~~
### `Table`
```go
Table([]string{"Name", "Age"}, [][]string{{"John", "21"}, {"Jane", "22"}})
```
> | Name | Age |
> | ---- | --- |
> | John | 21 |
> | Jane | 22 |
---
## 📄 License
This project is licensed under the [MIT License](LICENSE) - see the [LICENSE](LICENSE) file for details