Implemented Markdown escaping for render output
All checks were successful
ci/woodpecker/tag/release Pipeline was successful

This commit is contained in:
2026-05-24 18:13:05 -05:00
parent 0dfd06c349
commit 0fc92f3643
2 changed files with 77 additions and 6 deletions

View File

@@ -17,13 +17,13 @@ func (MarkdownRenderer) Render(transcript Transcript, opts Options) (string, err
if title == "" {
title = "Transcript"
}
lines = append(lines, "# "+title, "")
lines = append(lines, "# "+escapeMarkdownInline(title), "")
if opts.IncludeMetadata {
lines = append(lines,
fmt.Sprintf("- Application: %s", transcript.Metadata.Application),
fmt.Sprintf("- Version: %s", transcript.Metadata.Version),
fmt.Sprintf("- Output schema: %s", transcript.Schema),
fmt.Sprintf("- Application: %s", escapeMarkdownInline(transcript.Metadata.Application)),
fmt.Sprintf("- Version: %s", escapeMarkdownInline(transcript.Metadata.Version)),
fmt.Sprintf("- Output schema: %s", escapeMarkdownInline(transcript.Schema)),
"",
)
}
@@ -37,11 +37,11 @@ func (MarkdownRenderer) Render(transcript Transcript, opts Options) (string, err
parts = append(parts, fmt.Sprintf("[#%d]", segment.ID))
}
text := segment.Text
text := escapeMarkdownInline(segment.Text)
if shouldItalicize(segment.Categories) {
text = "*" + text + "*"
}
parts = append(parts, fmt.Sprintf("**%s:** %s", segment.Speaker, text))
parts = append(parts, fmt.Sprintf("**%s:** %s", escapeMarkdownInline(segment.Speaker), text))
lines = append(lines, strings.Join(parts, " "))
lines = append(lines, "")
}
@@ -53,6 +53,28 @@ func (MarkdownRenderer) Render(transcript Transcript, opts Options) (string, err
return output, nil
}
func escapeMarkdownInline(value string) string {
replacer := strings.NewReplacer(
`\`, `\\`,
"`", "\\`",
"*", "\\*",
"_", "\\_",
"{", "\\{",
"}", "\\}",
"[", "\\[",
"]", "\\]",
"(", "\\(",
")", "\\)",
"#", "\\#",
"+", "\\+",
"!", "\\!",
"|", "\\|",
"<", "\\<",
">", "\\>",
)
return replacer.Replace(value)
}
func shouldItalicize(categories []string) bool {
for _, category := range categories {
switch category {