htmlutil

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateHTMLClayID

func GenerateHTMLClayID() (string, error)

GenerateHTMLClayID generates a UUID v4 using crypto/rand.

func HasHTMLTag

func HasHTMLTag(data []byte) bool

HasHTMLTag reports whether data contains a real top-level <html> start tag, ignoring any <html occurrence inside a comment. Used to reject a save body that is not a full HTML document before it overwrites a file.

func InjectBanner added in v1.3.0

func InjectBanner(data, wrappedBanner []byte) []byte

InjectBanner inserts an already-wrapped banner immediately before the real top-level </html> end tag, using the same comment- and raw-text-aware scan as IsCompleteHTMLDocument, so a fake close tag inside a script or comment cannot misplace it. Position in the DOM is irrelevant to a fixed-position banner, and inserting at the end sidesteps every head/body reparenting subtlety an injection near <html> would raise. A document with no close tag gets the banner appended; one with no <html> tag at all is returned unchanged (served plain rather than guessed at).

func InjectHTMLClayID

func InjectHTMLClayID(data []byte, id string) []byte

InjectHTMLClayID adds htmlclayid to <html> if not already present. This is persistent — never stripped on save.

func InjectToken

func InjectToken(data []byte, value string) []byte

InjectToken injects the htmlclaytoken attribute on <html>. Ephemeral auth token — stripped on save.

func IsCompleteHTMLDocument added in v1.2.0

func IsCompleteHTMLDocument(data []byte) bool

IsCompleteHTMLDocument reports whether data is a whole document: a real top-level <html> start tag followed by a matching </html> end tag. HasHTMLTag alone is not sufficient for a restore, because it accepts `<html><body>partial` and would let a truncated version overwrite a good file.

func ReadHTMLClayID

func ReadHTMLClayID(data []byte) string

ReadHTMLClayID extracts the htmlclayid UUID from the <html> tag. Returns empty string if not present.

func SetHTMLClayID added in v1.2.0

func SetHTMLClayID(data []byte, id string) []byte

SetHTMLClayID forces htmlclayid on <html>, replacing any existing value. Restore uses it to keep the target file's canonical identity rather than adopting the id stored inside the restored version.

func StripBanner added in v1.3.0

func StripBanner(data []byte) []byte

StripBanner removes every marker-delimited banner from data. It runs on every save and restore: a banner that reached a token-holding tab (for instance pushed through live-sync into an edit-mode page) must never autosave itself into the file on disk. An unterminated start marker strips nothing rather than guessing at an end.

func StripHTMLClayID added in v1.2.0

func StripHTMLClayID(data []byte) []byte

StripHTMLClayID removes the htmlclayid attribute from <html>. Used when restoring into a file that carries no identity of its own, so a version taken from a different file cannot donate its id.

func StripToken

func StripToken(data []byte) []byte

StripToken removes the htmlclaytoken attribute from <html>.

func WrapBanner added in v1.3.0

func WrapBanner(banner []byte) []byte

WrapBanner surrounds server-authored banner markup with the strip markers.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL