This package helps in generating markdown in a declarative way without having to handle strings yourself
This README has been generated using this own package! You can see the code example here
- git
- go 1.16
go get github.com/simonecorsi/go-declarative-markdown
package main
import mkd "github.com/simonecorsi/go-declarative-markdown/markdown"
function main() {
md := mkd.CreateMarkdown("My h1 Header")
md.Header("About")
md.Paragraph("Lorem Ipsum")
md.Render() // save to file or whatever
}
CreateMarkdown(title string) *Markdown
Initialize new Markdown instance with h1 title on top.
Returns reference to the Markdown to allow chaining
GetLine(lineNumber int) string
Utilities to get a line in the markdown, this is a slice before rendering so LineBreak don't counts
Render() string
Renders all the content add in this markdown instance
Header(text string, weigth int) *Markdown
Creates an heading, you can specify the weigth [1-6]
Returns reference to the Markdown to allow chaining
AddLine(text string) *Markdown
Utilities that pushes content to the slices of lines, this is used internally by each other command
Returns reference to the Markdown to allow chaining
Paragraph(text string) *Markdown
Create a generic paragraph of text
Returns reference to the Markdown to allow chaining
Quote(text string) *Markdown
Create quoted paragraph of text
Returns reference to the Markdown to allow chaining
Code(text string, language string) *Markdown
Creates a snippet of code with syntax highligh
Returns reference to the Markdown to allow chaining
HorizontalLine() *Markdown
Creates an horizontal line to dive sections
Returns reference to the Markdown to allow chaining
Image(altText string, filepath string) *Markdown
Creates an image with a title
Returns reference to the Markdown to allow chaining
List(items []ListItem, numbered bool) *Markdown
Creates a list of item, either numbered or with dashes, default to dashes
Returns reference to the Markdown to allow chaining
type ListItem struct {
Label string
Depth int
}
Task(items []TaskItem, numbered bool) *Markdown
Creates a list with checkboxes
Returns reference to the Markdown to allow chaining
type TaskItem struct {
Label string
Checked bool
}
Table(headers []string, rows [][]string) *Markdown
Creates a table
Returns reference to the Markdown to allow chaining
GenerateToc(index int) *Markdown
Creates table of content and adds it after the main h1 title, call it before rendering!
Project is pretty simple and straight forward for what is my needs, but if you have any idea you're welcome.
This projects uses Conventional Commit Format so be sure to use standard commit format or PR won't be accepted
Distributed under the MIT License. See LICENSE
for more information.
Simone Corsi - @im_simonecorsi