mirror of
https://github.com/imjasonh/cnotes
synced 2026-07-19 07:08:17 +00:00
Improve conversation excerpt formatting in notes show command
- Added formatConversationExcerpt function to properly unescape JSON strings - Replaced escaped newlines (\n) with actual newlines for readability - Unescaped quotes, backslashes, tabs, and other JSON escape sequences - Tool interactions and conversation context now display with proper formatting - Much more readable output with proper line breaks and structure The conversation context is now properly formatted and easy to read instead of being one long escaped string.
This commit is contained in:
parent
997a55970f
commit
ad3c31ffea
1 changed files with 26 additions and 1 deletions
27
cmd/notes.go
27
cmd/notes.go
|
|
@ -166,13 +166,38 @@ func printConversationMarkdown(note notes.ConversationNote, commit string) {
|
|||
// Conversation excerpt
|
||||
if note.ConversationExcerpt != "" {
|
||||
fmt.Printf("## Conversation Context\n\n")
|
||||
fmt.Printf("%s\n\n", note.ConversationExcerpt)
|
||||
// Clean up and format the conversation excerpt for better readability
|
||||
formatted := formatConversationExcerpt(note.ConversationExcerpt)
|
||||
fmt.Printf("%s\n\n", formatted)
|
||||
}
|
||||
|
||||
fmt.Printf("---\n")
|
||||
fmt.Printf("💡 *Generated by Claude Code hooks system*\n")
|
||||
}
|
||||
|
||||
// formatConversationExcerpt cleans up the conversation excerpt for better readability
|
||||
func formatConversationExcerpt(excerpt string) string {
|
||||
// Replace escaped newlines with actual newlines
|
||||
formatted := strings.ReplaceAll(excerpt, "\\n", "\n")
|
||||
|
||||
// Replace escaped quotes with regular quotes
|
||||
formatted = strings.ReplaceAll(formatted, "\\\"", "\"")
|
||||
|
||||
// Replace escaped backslashes
|
||||
formatted = strings.ReplaceAll(formatted, "\\\\", "\\")
|
||||
|
||||
// Clean up common JSON escape sequences
|
||||
formatted = strings.ReplaceAll(formatted, "\\t", " ") // tabs to spaces
|
||||
formatted = strings.ReplaceAll(formatted, "\\r", "") // remove carriage returns
|
||||
|
||||
// Fix any double newlines that might have been created
|
||||
for strings.Contains(formatted, "\n\n\n") {
|
||||
formatted = strings.ReplaceAll(formatted, "\n\n\n", "\n\n")
|
||||
}
|
||||
|
||||
return strings.TrimSpace(formatted)
|
||||
}
|
||||
|
||||
// getCommitInfo returns formatted commit information
|
||||
func getCommitInfo(commit string) string {
|
||||
cmd := exec.Command("git", "log", "--oneline", "-1", commit)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue