xonecas.io
62159
Sy

symb / commit ce3f181

feat: markdown rendering for user and assistant messages

xonecas2026-02-14 ce3f181776b0c9396590ad21d3f87eb82ffab6a8 parent 2a44236

2 files changed

internal/tui/conv.go+20−1
@@ -4,6 +4,8 @@ import (
44 "strings"
55
66 "charm.land/lipgloss/v2"
7+ "github.com/xonecas/symb/internal/constants"
8+ "github.com/xonecas/symb/internal/highlight"
79 )
810
911 // ---------------------------------------------------------------------------
@@ -13,6 +15,23 @@ import (
1315 // convWidth returns the usable width of the conversation pane.
1416 func (m Model) convWidth() int { return m.layout.conv.Dx() }
1517
18+// highlightMarkdown highlights markdown text line-by-line via Chroma.
19+// Line-by-line keeps each call tiny and cacheable, so streaming stays fast.
20+// Fenced code blocks lose inner language highlighting but delimiters are styled.
21+func highlightMarkdown(text string, fallback lipgloss.Style) []string {
22+ raw := strings.Split(text, "\n")
23+ out := make([]string, len(raw))
24+ for i, line := range raw {
25+ hl := highlight.CachedHighlight(line, "markdown", constants.SyntaxTheme, "#000000")
26+ if hl == line {
27+ out[i] = fallback.Render(line)
28+ } else {
29+ out[i] = hl
30+ }
31+ }
32+ return out
33+}
34+
1635 // styledLines applies a lipgloss style to each line in a multi-line text.
1736 // No wrapping — lines are stored raw for later wrapping at render time.
1837 func styledLines(text string, style lipgloss.Style) []string {
@@ -60,7 +79,7 @@ func (m *Model) rebuildStreamEntries() {
6079 m.convEntries = append(m.convEntries, textEntries(styledLines(m.streamingReasoning, m.styles.Muted)...)...)
6180 }
6281 if m.streamingContent != "" {
63- m.convEntries = append(m.convEntries, textEntries(styledLines(m.streamingContent, m.styles.Text)...)...)
82+ m.convEntries = append(m.convEntries, textEntries(highlightMarkdown(m.streamingContent, m.styles.Text)...)...)
6483 }
6584
6685 // Incrementally re-wrap only the streaming entries.
internal/tui/update.go+2−2
@@ -179,7 +179,7 @@ func (m *Model) handleUserMsg(msg llmUserMsg) Model {
179179 dbMsgID: dbMsgID,
180180 })
181181
182- m.appendText(styledLines(msg.content, m.styles.Text)...)
182+ m.appendText(highlightMarkdown(msg.content, m.styles.Text)...)
183183 m.appendText("")
184184 sep := m.makeSeparator("0s", now.Format("15:04:05"))
185185 wasBottom := m.appendText(sep)
@@ -277,7 +277,7 @@ func (m *Model) applyAssistantMsg(msg llmAssistantMsg) {
277277 }
278278 }
279279 if msg.content != "" {
280- wasBottom := m.appendText(styledLines(msg.content, m.styles.Text)...)
280+ wasBottom := m.appendText(highlightMarkdown(msg.content, m.styles.Text)...)
281281 m.appendText("")
282282 if wasBottom {
283283 m.scrollOffset = 0