Skip to content

Commit

Permalink
escape html
Browse files Browse the repository at this point in the history
  • Loading branch information
pilcrowOnPaper committed Mar 9, 2024
1 parent 6f889a3 commit c561d9f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/commands/build/code-block-links.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package build
import (
"bytes"
"fmt"
"html"
"strings"

"github.com/alecthomas/chroma"
"github.com/alecthomas/chroma/formatters/html"
htmlFormatter "github.com/alecthomas/chroma/formatters/html"
"github.com/alecthomas/chroma/lexers"
"github.com/alecthomas/chroma/styles"
"github.com/yuin/goldmark/ast"
Expand Down Expand Up @@ -66,13 +67,13 @@ func (r codeBlockLinksRenderer) renderCustomCodeBlockLinks(w util.BufWriter, sou
lexer := lexers.Get(string(codeBlock.Language(source)))
if lexer == nil {
w.WriteString("<pre class=\"codeblock\"><code>")
w.WriteString(content)
w.WriteString(html.EscapeString(content))
w.WriteString("</code></pre>")
return ast.WalkContinue, nil
}
lexer = chroma.Coalesce(lexer)

formatter := html.New(html.WithClasses(true), html.PreventSurroundingPre(true))
formatter := htmlFormatter.New(htmlFormatter.WithClasses(true), htmlFormatter.PreventSurroundingPre(true))

iterator, err := lexer.Tokenise(nil, content)
if err != nil {
Expand Down

0 comments on commit c561d9f

Please sign in to comment.