aboutsummaryrefslogtreecommitdiff
path: root/lib/net/html/example_test.go
AgeCommit message (Collapse)Author
2024-03-09lib: move package "net/html" to "lib/html"Shulhan
Putting "html" under "net" package make no sense. Another reason is to make the package flat under "lib/" directory.
2024-03-05all: comply with linter recommendations #2Shulhan
HTTP request now implicitly create request with context. Any false positive related to not closing HTTP response body has been annotated with "nolint:bodyclose". In the example code, use consistent "// Output:" comment format, by prefixing with single space. Any comment on code now also prefixing with single space. An error returned without variables now use [errors.New] instead of [fmt.Errorf]. Any error returned using [fmt.Errorf] now wrapped using "%w" instead of "%s". Also, replace error checking using [errors.Is] or [errors.As], instead of using equal/not-equal operator. Any statement like "x = x OP y" now replaced with "x OP= y". Also, swap statement is simplified using "x, y = y, x". Any switch statement with single case now replaced with if-condition. Any call to defer on function or program that call [os.Exit], now replaced by calling the deferred function directly. Any if-else condition now replaced with switch statement, if possible.
2022-07-02net/html: use inline replacement to clean up white spacesShulhan
Instead of using bytes.Replace, three times, iterate the plain text manually to clean up the white and multiple spaces. Benchmark result, name old time/op new time/op delta Sanitize-8 4.27µs ±10% 2.64µs ±13% -38.21% (p=0.000 n=10+10) name old alloc/op new alloc/op delta Sanitize-8 4.84kB ± 0% 4.45kB ± 0% -7.94% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Sanitize-8 13.0 ± 0% 6.0 ± 0% -53.85% (p=0.000 n=10+10)
2022-06-27all: move lib/sanitize.HTML to net/html.SanitizeShulhan
Since the sanitize package only contains HTML function, and the html package already exist, we move the function into html package.
2022-06-27net/html: convert the NormalizeForID input letters to lower caseShulhan
While at it, minimize allocation by using the input []byte as output.
2022-06-24net/html: add function NormalizeForIDShulhan
Given an input string, The NormalizeForID normalize it to HTML ID. The normalization follow Mozilla specification [1] rules, - it must not contain whitespace (spaces, tabs etc.), - only ASCII letters, digits, '_', and '-' should be used, and - it should start with a letter. An empty string is equal to "_". Any other unknown characters will be replaced with '_'. If the input does not start with letter, it will be prefixed with '_', unless it start with '_'. [1] https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id.