Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/cugu/md

⬇️ Parse markdown into Go structs, similar to encoding/json.
https://github.com/cugu/md

go markdown

Last synced: about 5 hours ago
JSON representation

⬇️ Parse markdown into Go structs, similar to encoding/json.

Awesome Lists containing this project

README

        

# md

[![Go Reference](https://pkg.go.dev/badge/image)](https://pkg.go.dev/github.com/cugu/md)
[![Go Coverage](https://github.com/cugu/md/wiki/coverage.svg)](https://raw.githack.com/wiki/cugu/md/coverage.html)

Parse markdown into Go structs, similar to encoding/json.

Supports parsing markdown into structs with the following fields:

- `heading`: A Markdown heading (e.g. `# Title`).
- `paragraph`: A Markdown paragraph (e.g. `A short description.`).
- `blockquote`: A Markdown blockquote (e.g. `> A blockquote.`).
- `thematic_break`: A Markdown thematic break (e.g. `---`).
- `code_block`: A Markdown code block (e.g. ```` ```go\nfunc main() {}``` ````).

## Example

Parse a markdown file into a struct.

```go
package main

import (
"fmt"

"github.com/cugu/md"
)

type Text struct {
Title string `md:"heading"`
Description string `md:"paragraph"`
}

const example = `
# Title

A short description.
`

func main() {
var text Text
if err := md.Unmarshal([]byte(example), &text); err != nil {
fmt.Println(err)
return
}

fmt.Println(text.Title)
fmt.Println(text.Description)
// Output:
// Title
// A short description.
}
```