Skip to content

Commit 15f140f

Browse files
committed
disable html escape for @Format
1 parent 3da1423 commit 15f140f

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

internal/ext/format/json.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package format
22

33
import (
4+
"bytes"
45
"encoding/json"
56

67
"github.com/ImSingee/go-ex/ee"
@@ -17,7 +18,17 @@ func (f *JsonFormatter) Format(filename string, content []byte) ([]byte, error)
1718
return nil, ee.New("invalid json")
1819
}
1920

20-
return json.MarshalIndent(v, "", f.Indent)
21+
var buf bytes.Buffer
22+
encoder := json.NewEncoder(&buf)
23+
encoder.SetEscapeHTML(false)
24+
encoder.SetIndent("", f.Indent)
25+
26+
err = encoder.Encode(v)
27+
if err != nil {
28+
return nil, err
29+
}
30+
31+
return bytes.TrimSuffix(buf.Bytes(), []byte("\n")), nil
2132
}
2233

2334
func (o *options) jsonFormatter() *JsonFormatter {

0 commit comments

Comments
 (0)