checker/html_escape.go
Onur Cinar 4a77e34c92
Doc automation. (#126)
# Describe Request

Doc automation.

# Change Type

Doc update.
2024-10-29 21:10:40 -07:00

31 lines
782 B
Go

// Copyright (c) 2023-2024 Onur Cinar.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
// https://github.com/cinar/checker
package checker
import (
"html"
"reflect"
)
// tagHTMLEscape is the tag of the normalizer.
const tagHTMLEscape = "html-escape"
// makeHTMLEscape makes a normalizer function for the HTML escape normalizer.
func makeHTMLEscape(_ string) CheckFunc {
return normalizeHTMLEscape
}
// normalizeHTMLEscape applies HTML escaping to special characters.
// Uses html.EscapeString for the actual escape operation.
func normalizeHTMLEscape(value, _ reflect.Value) error {
if value.Kind() != reflect.String {
panic("string expected")
}
value.SetString(html.EscapeString(value.String()))
return nil
}