https://github.com/kruceo/marceo-go
A rewrite of the markdown-html parser Marceo, but in golang, focusing in performance.
https://github.com/kruceo/marceo-go
go html markdown parser performance speed
Last synced: 2 months ago
JSON representation
A rewrite of the markdown-html parser Marceo, but in golang, focusing in performance.
- Host: GitHub
- URL: https://github.com/kruceo/marceo-go
- Owner: Kruceo
- License: mit
- Created: 2024-03-15T13:43:58.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-26T16:52:55.000Z (over 2 years ago)
- Last Synced: 2025-06-20T14:43:24.164Z (about 1 year ago)
- Topics: go, html, markdown, parser, performance, speed
- Language: Go
- Homepage:
- Size: 2.39 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Marceo Go
[](https://github.com/Kruceo/marceo-go/actions/workflows/build.yml)
[](https://github.com/kruceo/marceo-go/issues)
[](https://github.com/kruceo/marceo-go/blob/master/LICENSE)
[](https://github.com/kruceo/marceo/releases)
## 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
```bash
git clone https://github.com/Kruceo/marceo-go.git
cd marceo-go
go build
```
## Basic CLI Usage
```bash
./marceo -i ./my/text.md -o ./my/output.html
```
## Using in own projects
### Install
```bash
go get github.com/kruceo/marceo-go
```
### Basic Parse
```go
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.
```go
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.
```go
// 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 "" + c + ""
}
// 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
```go
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 `paralelism`.
|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|