https://github.com/delthas/discord-formatting
A small Go library for parsing Discord markdown-like messages to an AST
https://github.com/delthas/discord-formatting
ast discord formatting markdown parser
Last synced: about 2 months ago
JSON representation
A small Go library for parsing Discord markdown-like messages to an AST
- Host: GitHub
- URL: https://github.com/delthas/discord-formatting
- Owner: delthas
- License: mit
- Created: 2022-07-28T23:23:10.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-07-30T15:21:38.000Z (almost 4 years ago)
- Last Synced: 2025-01-11T02:48:19.411Z (over 1 year ago)
- Topics: ast, discord, formatting, markdown, parser
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# discord-formatting [](https://godoc.org/github.com/delthas/discord-formatting) [](https://github.com/emersion/stability-badges#experimental)
A small Go library for parsing Discord markdown-like messages to an AST.
The goal is to copy the Discord apps behavior as precisely as possible. This is not a general purpose Markdown parser.
## Usage
The API is well-documented in its [](https://godoc.org/github.com/delthas/discord-formatting)
### Example
```go
package main
import "github.com/delthas/discord-formatting"
func main() {
parser := formatting.NewParser(nil)
ast := parser.Parse("*hi* @everyone <:smile:12345> __what__ **is** `up`?")
formatting.Walk(ast, func(n formatting.Node, entering bool) {
switch nn := n.(type) {
case *formatting.TextNode:
if entering {
fmt.Print(nn.Content)
}
}
})
fmt.Println(formatting.Debug(ast))
}
```
## Status
Used daily in a small-scale deployment.
The API could be slightly changed in backwards-incompatible ways for now.
- [X] Nearly all the formatting
- [ ] Replacing Unicode named emoji with their actual emoji codepoints
## License
MIT