Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/cugu/md
- Owner: cugu
- License: mit
- Created: 2024-03-17T22:39:05.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-05-22T06:33:29.000Z (8 months ago)
- Last Synced: 2024-11-11T02:11:38.211Z (about 2 months ago)
- Topics: go, markdown
- Language: Go
- Homepage:
- Size: 16.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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 mainimport (
"fmt""github.com/cugu/md"
)type Text struct {
Title string `md:"heading"`
Description string `md:"paragraph"`
}const example = `
# TitleA 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.
}
```