Skip to content

Commit

Permalink
fix: escape some characters in title/alt for figure
Browse files Browse the repository at this point in the history
1. Escape double quotes
2. Remove \n

There might still be some other edge cases that I can't seem to think of
right now. I cannot find a proper way for escaping this, so, I have to
do this patchwork.

Ref: #67
  • Loading branch information
ashishb committed Oct 12, 2024
1 parent e33ea8a commit cefbbbe
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ func galleryReplacementFunction(provider ImageURLProvider, galleryInfo string) (
src = strings.ReplaceAll(src, " ", "%20")
src = strings.ReplaceAll(src, "_", "%5F")

title := tmp.Title
// Escape weird characters in title
title := strings.ReplaceAll(tmp.Title, `"`, `\"`)
title = strings.ReplaceAll(title, "\n", " ")

output.WriteString("<br>") // This will get converted to newline later on
output.WriteString(fmt.Sprintf(`{{< figure src="%s" title="%s" alt="%s" >}}`, src, title, title))
Expand Down

0 comments on commit cefbbbe

Please sign in to comment.