<commit_before># Mark [![Test coverage][coveralls-image]][coveralls-url] [![Build status][travis-image]][travis-url]
> A [markdown](http://daringfireball.net/projects/markdown/) processor written in Go. built for fun.

This project inspired from [<NAME> - Lexical Scanning talk](https://www.youtube.com/watch?v=HxaD_trXwRE) and [marked](https://github.com/chjj/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](#get-started)
- [Examples](#examples)
- [Documentation](#documentation)
    - [Render](#render)
    - [type Mark](#mark)
        - [New](#new)
        - [AddRenderFn](#markaddrenderfn)
        - [Render](#markrender)
    - [smartypants and smartfractions](smartypants-and-smartfractions)
- [Todo](#todo)

### Get Started
#### Installation
```sh
$ go get github.com/a8m/mark
```
#### Examples
__Add to your project:__
```go
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](https://github.com/a8m/mark-cli)__
```sh
$ echo 'hello __world__...' | mark-cli -smartypants
```

#### Documentation
##### Render
Staic rendering function.
```go
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`.
```go
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](http://godoc.org/github.com/a8m/mark)
```go
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.<commit_msg>docs(mark): add AddRenderFn example<commit_after># Mark [![Test coverage][coveralls-image]][coveralls-url] [![Build status][travis-image]][travis-url]
> A [markdown](http://daringfireball.net/projects/markdown/) processor written in Go. built for fun.

This project inspired from [<NAME> - Lexical Scanning talk](https://www.youtube.com/watch?v=HxaD_trXwRE) and [marked](https://github.com/chjj/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](#get-started)
- [Examples](#examples)
- [Documentation](#documentation)
    - [Render](#render)
    - [type Mark](#mark)
        - [New](#new)
        - [AddRenderFn](#markaddrenderfn)
        - [Render](#markrender)
    - [smartypants and smartfractions](smartypants-and-smartfractions)
- [Todo](#todo)

### Get Started
#### Installation
```sh
$ go get github.com/a8m/mark
```
#### Examples
__Add to your project:__
```go
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](https://github.com/a8m/mark-cli)__
```sh
$ echo 'hello __world__...' | mark-cli -smartypants
```

#### Documentation
##### Render
Staic rendering function.
```go
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`.
```go
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](http://godoc.org/github.com/a8m/mark)  

Example 1:
```go
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>
```

Example 2:
```go
m := mark.New("# Hello world", &mark.Options{
	Smartypants: true,
	Fractions:   true,
})
m.AddRenderFn(mark.NodeHeading, func(node mark.Node) string {
	h, _ := node.(*mark.HeadingNode)
	return fmt.Sprintf("<angular-heading-directive level=\"%d\" text=\"%s\"/>", h.Level, h.Text)
})
fmt.Println(m.Render())
// <angular-heading-directive level="1" text="Hello world"/>
```

##### Mark.Render
Parse and render input.
{'fraction_non_alphanumeric': 0.1904127829560586, 'fraction_numerical': 0.002092448164352292, 'mean_word_length': 4.002854424357754, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 37, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2415792', 'n_tokens_mistral': 1879, 'n_tokens_neox': 1790, 'n_words': 471}