Added RawText type
This commit is contained in:
parent
f80148fdf6
commit
ae85431082
@ -1,6 +1,10 @@
|
||||
# Changelog
|
||||
|
||||
## Unversioned
|
||||
## [0.0.4] - 2019-05-27
|
||||
|
||||
### Added
|
||||
|
||||
- `hatmill.RawText` type for unescaped text nodes
|
||||
|
||||
### Changed
|
||||
|
||||
|
16
hatmill.go
16
hatmill.go
@ -165,7 +165,21 @@ func (t Text) WriteTo(w io.Writer) (n int64, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// WriteDocument writes an HTML5 doctype declaration, followed by root.
|
||||
// RawText represents an HTML text node. Unlike Text, its contents are not
|
||||
// escaped when written, so it should be used with care. It is intended mainly
|
||||
// for use in <style> and <script> elements.
|
||||
type RawText string
|
||||
|
||||
func (RawText) isHtml() {}
|
||||
|
||||
// WriteTo writes the contents of t to w, returning the number of bytes written
|
||||
// and any error encountered. It does not escape special characters.
|
||||
func (t RawText) WriteTo(w io.Writer) (n int64, err error) {
|
||||
err = writeStringsTo(w, &n, string(t))
|
||||
return
|
||||
}
|
||||
|
||||
// WriteDocument writes an HTML5 DOCTYPE declaration, followed by root.
|
||||
// root should probably be an <html> element.
|
||||
func WriteDocument(w io.Writer, root ParentElement) (n int64, err error) {
|
||||
err = writeStringsTo(w, &n, "<!DOCTYPE html>")
|
||||
|
@ -231,6 +231,13 @@ func TestTerms(t *testing.T) {
|
||||
))
|
||||
}
|
||||
|
||||
func ExampleRawText() {
|
||||
he.Style()(
|
||||
hatmill.RawText(`div > p::before {content: "Words & stuff: ";}`),
|
||||
).WriteTo(os.Stdout)
|
||||
// Output: <style>div > p::before {content: "Words & stuff: ";}</style>
|
||||
}
|
||||
|
||||
func Example() {
|
||||
userInput := "<script>launchMissiles();</script>"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user