1
0
Fork 0
mirror of https://github.com/diamondburned/cchat-discord.git synced 2024-11-21 21:52:46 +00:00

fixed codeblocks

This commit is contained in:
diamondburned 2020-11-05 22:14:52 -08:00
parent 37165658e1
commit fc795ef7b6
4 changed files with 15 additions and 16 deletions

View file

@ -80,9 +80,10 @@ func NewMessageUpdateContent(msg discord.Message, s *state.Instance) Message {
}
}
var content = segments.ParseMessage(&msg, s.Store)
return Message{
messageHeader: newHeader(msg),
content: segments.ParseMessage(&msg, s.Store),
content: content,
}
}

View file

@ -8,7 +8,7 @@ import (
)
func init() {
renderer.Register(ast.KindCodeBlock, codeblock)
renderer.Register(ast.KindFencedCodeBlock, codeblock)
}
func codeblock(r *renderer.Text, node ast.Node, enter bool) ast.WalkStatus {

View file

@ -7,6 +7,14 @@ import (
"github.com/diamondburned/cchat-discord/internal/segments/renderer"
"github.com/diamondburned/cchat/text"
"github.com/diamondburned/ningen/md"
_ "github.com/diamondburned/cchat-discord/internal/segments/blockquote"
_ "github.com/diamondburned/cchat-discord/internal/segments/codeblock"
_ "github.com/diamondburned/cchat-discord/internal/segments/colored"
_ "github.com/diamondburned/cchat-discord/internal/segments/emoji"
_ "github.com/diamondburned/cchat-discord/internal/segments/inline"
_ "github.com/diamondburned/cchat-discord/internal/segments/link"
_ "github.com/diamondburned/cchat-discord/internal/segments/mention"
)
func ParseMessage(m *discord.Message, s state.Store) text.Rich {

View file

@ -3,6 +3,7 @@ package renderer
import (
"bytes"
"fmt"
"log"
"github.com/diamondburned/arikawa/discord"
"github.com/diamondburned/arikawa/state"
@ -18,6 +19,7 @@ var renderers = map[ast.NodeKind]Renderer{}
// Register registers a renderer to a node kind.
func Register(kind ast.NodeKind, r Renderer) {
log.Printf("Registering kind %v", kind)
renderers[kind] = r
}
@ -185,6 +187,8 @@ func (r *Text) RenderNode(n ast.Node, enter bool) (ast.WalkStatus, error) {
return f(r, n, enter), nil
}
log.Println("unknown kind:", n.Kind())
switch n := n.(type) {
case *ast.Document:
case *ast.Paragraph:
@ -192,20 +196,6 @@ func (r *Text) RenderNode(n ast.Node, enter bool) (ast.WalkStatus, error) {
// TODO: investigate
// r.Buffer.WriteByte('\n')
}
// case *ast.Blockquote:
// return r.blockquote(n, enter), nil
// case *ast.FencedCodeBlock:
// return r.codeblock(n, enter), nil
// case *ast.Link:
// return r.link(n, enter), nil
// case *ast.AutoLink:
// return r.autoLink(n, enter), nil
// case *md.Inline:
// return r.inline(n, enter), nil
// case *md.Emoji:
// return r.emoji(n, enter), nil
// case *md.Mention:
// return r.mention(n, enter), nil
case *ast.String:
if enter {
r.Buffer.Write(n.Value)