Skip to content

A rewrite of the markdown-html parser Marceo, but in golang, focusing in performance.

License

Notifications You must be signed in to change notification settings

Kruceo/Marceo-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Marceo Go

Build GitHub issues License Latest Version

Description

Marceo-Go is a rewrite from Marceo, a markdown-html parser, but built to js.

  • Focused on speed.
  • Can be used directly in CLI
  • Can be used as dependency.

Building from sources

git clone https://github.com/Kruceo/marceo-go.git
cd marceo-go
go build

Basic CLI Usage

./marceo -i ./my/text.md -o ./my/output.html

Using in own projects

Install

go get github.com/kruceo/marceo-go

Basic Parse

import "github.com/kruceo/marceo-go/library/packs"

func main(){
    myMarkdown := "# This is a **Title**"

    // The default pack of plugins by Marceo
    pack := packs.DefaultPack

    result := pack.Parse(myMarkdown)

    println(result)
}

Creating my own pack

With Marceo-go you will be able to create a pack with selected (or with your owns) plugins.

import (
	"github.com/kruceo/marceo-go/library/classes"
	"github.com/kruceo/marceo-go/library/plugins"
)

func main() {
	// Added only Headers 1 `#` and Anchors `[text](url)`
	myPack := classes.NewPack(plugins.Header1, plugins.Anchor)

	res1 := myPack.Parse("# My header 1 that will be parsed.")
	res2 := myPack.Parse("## My header 2 that not will be parsed.")
	res3 := myPack.Parse("[My anchor](https://kruceo.com)")

	println(res1)
	println(res2)
	println(res3)
}

Creating a Plugin

To create plugins you will especially need to known a bit of regex expressions.

// This will capture the text between ">" and "<".
var Regex *regexp.Regexp = regexp.MustCompile(`(>)(.+?)(<)`)

// "start", "content" and "end" args.
func Replacer(s, c, e string) string {
	//process your strings.
	return "<myOwnTag>" + c + "</myOwnTag>"
}

// This changes some behaviors on parse
var pluginOptions classes.PluginOptions = classes.PluginOptions{}

// Finally create the plugin
var myPlugin classes.Plugin = classes.NewPlugin("MyPlugin", *Regex, Replacer, pluginOptions)

Testing the plugin

func main() {
	myPack := classes.NewPack(myPlugin)

	res := myPack.Parse("# >This is a test<")

	println(res)
}

Benchmarks

Benchmark from 26/03/2023 - v0.6.4

The benchmark was run with the -p option for parallelism.

Total Words Markdown Words Execution Time
70 50 4ms
734 500 8ms
6470 5000 57ms

Testing Machine

OS KERNEL CPU MEM STO
Arch Linux Linux 6.7.4-arch1-1 Intel® Core™ i3-1005G1 8,0 GiB NVME 1200 mb/s R&W

About

A rewrite of the markdown-html parser Marceo, but in golang, focusing in performance.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages