Fix new line literal in embed (#237)

This commit is contained in:
Thomas Miceli 2024-04-02 17:12:29 +02:00
parent 1c1e3a8919
commit c185cb8933
1 changed files with 3 additions and 2 deletions

View File

@ -443,8 +443,9 @@ func gistJs(ctx echo.Context) error {
js := `document.write('<link rel="stylesheet" href="%s">')
document.write('%s')
`
js = fmt.Sprintf(js, cssUrl,
strings.Replace(htmlbuf.String(), "\n", `\n`, -1))
content := strings.Replace(htmlbuf.String(), `\n`, `\\n`, -1)
content = strings.Replace(content, "\n", `\n`, -1)
js = fmt.Sprintf(js, cssUrl, content)
ctx.Response().Header().Set("Content-Type", "application/javascript")
return plainText(ctx, 200, js)
}