• This repository has been archived on 09/Sep/2019
  • Stars
    star
    203
  • Rank 192,890 (Top 4 %)
  • Language
    Go
  • License
    MIT License
  • Created over 9 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A markdown processor written in Go. built for fun.

Archived. use https://github.com/russross/blackfriday instead

Mark Test coverage Build status Go doc license

A markdown processor written in Go. built for fun.

Mark is a markdown processor that supports all the features of GFM, smartypants and smart-fractions rendering.
It was built with a nice-ish concurrency model that fully inspired from Rob Pike - Lexical Scanning talk and marked project.
Please note that 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 as a command line tool:

1. install:

$ go get github.com/a8m/mark/cmd/mark

2. usage:

$ echo 'hello __world__...' | mark -smartypants

or:

$ mark -i hello.text -o hello.html

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

Example 1:

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:

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.

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

  • Commonmark support v0.2
  • Expand documentation
  • Configuration options
    • gfm, table
    • heading(auto hashing)

License

MIT

More Repositories

1

golang-cheat-sheet

An overview of Go syntax and features.
8,366
star
2

angular-filter

Bunch of useful filters for AngularJS (with no external dependencies!)
JavaScript
2,927
star
3

envsubst

Environment variables substitution for Go
Go
732
star
4

djson

Fast Go decoder for dynamic JSON
Go
601
star
5

pb

Console progress bar for Rust
Rust
580
star
6

reflect-examples

Bunch of examples for dealing with the reflect package
555
star
7

rql

Resource Query Language for REST
Go
337
star
8

syncmap

A typed implementation of the Go sync.Map using code generation
Go
256
star
9

play

Play something while waiting for your command to finish
Go
185
star
10

kinesis-producer

An aggregated records producer for Amazon Kinesis
Go
147
star
11

enter

A CLI for generating ER diagrams for Ent schema
Go
131
star
12

ng-pipes

Bunch of useful pipes for Angular2 (with no external dependencies!)
TypeScript
118
star
13

tree

An implementation of the Unix tree command written in Go, that can be used programmatically
Go
92
star
14

agile

Like Underscore, but with zero callbacks and really more fun, v0.0.2
JavaScript
69
star
15

ent-graphql-example

The code for https://entgo.io/docs/tutorial-setup
Go
60
star
16

doqmentdb

A Promise-Based DocumentDB ODM Client for NodeJS
JavaScript
52
star
17

ng-translation

Fast, Easy and Dynamic translation for AngularJS
JavaScript
43
star
18

pb-scala

Console progress bar for Scala
Scala
37
star
19

documentdb

Go driver for Microsoft Azure DocumentDB
Go
33
star
20

expect

Minimalistic BDD-style assertions for Go (inspired by expect.js)
Go
32
star
21

deep-keys

Create an array composed of the own enumerable property names (including nested) of an object.
JavaScript
23
star
22

lease

Generic lease implementation using DynamoDB
Go
20
star
23

angular-code-mirror

2 way binding codemirror for AngularJS based on google-prettify
JavaScript
13
star
24

entclean

Clean ent/schemas
Go
11
star
25

errors

An experimental error handling package for Go
Go
10
star
26

clog

Pretty colorful cli logger for NodeJS(with table, success and more...)
JavaScript
9
star
27

s3tree

s3tree is a tree command for Amazon S3
Go
7
star
28

entspatial

An example repository for working with MySQL spatial data types in ent
Go
7
star
29

gotips-talk-2018

"Did you know that..." talk. Go-Israel meetup, Jan 2018
Go
6
star
30

maman14

maman14 - assembler
C
5
star
31

go-documentdb-example

A users CRUD app using Martini and DocumentDB
Go
4
star
32

obj-parse

Get and Set object properties in a Fast and Elegant way. (with caching and no dependencies!)
JavaScript
4
star
33

obj-del

Remove multiple keys by path - safety.
JavaScript
3
star
34

entsize

Print ent/schema size
Go
3
star
35

flag.js

cli flag parsing
JavaScript
2
star
36

dynamose

A Promise-Based DynamoDB Client
JavaScript
2
star
37

ent-sync-example

The code for https://entgo.io/blog/2021/11/1/sync-objects-in-external-database
Go
2
star
38

stringify.js

like JSON.stringify, but more sense
JavaScript
1
star
39

mark-cli

Mark command-line tool
Go
1
star
40

koa-documentdb-example

A users CRUD app using Koa and DoQmentDB(DocumentDB wrapper)
JavaScript
1
star
41

obj-is

is-function's creator
JavaScript
1
star
42

entraffle

A raffle for Ent Discord members
Go
1
star