mirror of
https://github.com/diamondburned/cchat-discord.git
synced 2024-11-22 06:02:59 +00:00
fixed codeblocks
This commit is contained in:
parent
37165658e1
commit
fc795ef7b6
|
@ -80,9 +80,10 @@ func NewMessageUpdateContent(msg discord.Message, s *state.Instance) Message {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var content = segments.ParseMessage(&msg, s.Store)
|
||||||
return Message{
|
return Message{
|
||||||
messageHeader: newHeader(msg),
|
messageHeader: newHeader(msg),
|
||||||
content: segments.ParseMessage(&msg, s.Store),
|
content: content,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
renderer.Register(ast.KindCodeBlock, codeblock)
|
renderer.Register(ast.KindFencedCodeBlock, codeblock)
|
||||||
}
|
}
|
||||||
|
|
||||||
func codeblock(r *renderer.Text, node ast.Node, enter bool) ast.WalkStatus {
|
func codeblock(r *renderer.Text, node ast.Node, enter bool) ast.WalkStatus {
|
||||||
|
|
|
@ -7,6 +7,14 @@ import (
|
||||||
"github.com/diamondburned/cchat-discord/internal/segments/renderer"
|
"github.com/diamondburned/cchat-discord/internal/segments/renderer"
|
||||||
"github.com/diamondburned/cchat/text"
|
"github.com/diamondburned/cchat/text"
|
||||||
"github.com/diamondburned/ningen/md"
|
"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 {
|
func ParseMessage(m *discord.Message, s state.Store) text.Rich {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package renderer
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
"github.com/diamondburned/arikawa/discord"
|
"github.com/diamondburned/arikawa/discord"
|
||||||
"github.com/diamondburned/arikawa/state"
|
"github.com/diamondburned/arikawa/state"
|
||||||
|
@ -18,6 +19,7 @@ var renderers = map[ast.NodeKind]Renderer{}
|
||||||
|
|
||||||
// Register registers a renderer to a node kind.
|
// Register registers a renderer to a node kind.
|
||||||
func Register(kind ast.NodeKind, r Renderer) {
|
func Register(kind ast.NodeKind, r Renderer) {
|
||||||
|
log.Printf("Registering kind %v", kind)
|
||||||
renderers[kind] = r
|
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
|
return f(r, n, enter), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Println("unknown kind:", n.Kind())
|
||||||
|
|
||||||
switch n := n.(type) {
|
switch n := n.(type) {
|
||||||
case *ast.Document:
|
case *ast.Document:
|
||||||
case *ast.Paragraph:
|
case *ast.Paragraph:
|
||||||
|
@ -192,20 +196,6 @@ func (r *Text) RenderNode(n ast.Node, enter bool) (ast.WalkStatus, error) {
|
||||||
// TODO: investigate
|
// TODO: investigate
|
||||||
// r.Buffer.WriteByte('\n')
|
// 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:
|
case *ast.String:
|
||||||
if enter {
|
if enter {
|
||||||
r.Buffer.Write(n.Value)
|
r.Buffer.Write(n.Value)
|
||||||
|
|
Loading…
Reference in a new issue