# README
Mark

A markdown processor written in Go. built for fun.
This project inspired from Rob Pike - Lexical Scanning talk and marked project.
Please note that this is a WIP project and any contribution is welcomed and appreciated,
so feel free to take some task here.
Table of contents:
Get Started
Installation
$ go get github.com/a8m/mark
Examples
Add to your project:
import (
"fmt"
"github.com/a8m/mark"
)
func main() {
html := mark.Render("I am using __markdown__.")
fmt.Println(html)
// <p>I am using <strong>markdown</strong>.</p>
}
or using mark-cli
$ echo 'hello __world__...' | mark-cli -smartypants
Documentation
Render
Staic rendering function.
html := mark.Render("I am using __markdown__.")
fmt.Println(html)
// <p>I am using <strong>markdown</strong>.</p>
Mark
New
New
get string as an input, and mark.Options
as configuration and return a new Mark
.
m := mark.New("hello world...", &mark.Options{
Smartypants: true,
})
fmt.Println(m.Render())
// <p>hello world…</p>
// Note: you can instantiate it like so: mark.New("...", nil) to get the default options.
Mark.AddRenderFn
AddRenderFn
let you pass NodeType
, and RenderFn
function and override the default Node
rendering.
To get all Nodes type and their fields/methods, see the full documentation: go-doc
m := mark.New("hello", nil)
m.AddRenderFn(mark.NodeParagraph, func(node mark.Node) (s string) {
p, _ := node.(*mark.ParagraphNode)
s += "<p class=\"mv-msg\">"
for _, n := range p.Nodes {
s += n.Render()
}
s += "</p>"
return
})
fmt.Println(m.Render())
// <p class="mv-msg">hello</p>
Mark.Render
Parse and render input.
m := mark.New("hello", nil)
fmt.Println(m.Render())
// <p>hello</p>
Smartypants and Smartfractions
Mark also support smartypants and smartfractions rendering
func main() {
opts := mark.DefaultOptions()
opts.Smartypants = true
opts.Fractions = true
m := mark.New("'hello', 1/2 beer please...", opts)
fmt.Println(m.Render())
// ‘hello’, ½ beer please…
}
Todo
- Backslash escaping
- should ignore inside code spans
- Expand documentation
- Configuration options
- gfm, table
- heading(auto hashing)
License
MIT