Help us shape the future of Go! Take the 2026 Go Developer Survey

textdiff

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package textdiff compares what different agents were shown on a page.

Comparisons work on visible text, not raw HTML, so that nonces, CSRF tokens, inline scripts and attribute order do not count as differences.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Changed

func Changed(lines []Line) bool

Changed reports whether lines contain any insertion or deletion.

func Similarity

func Similarity(a, b string) float64

Similarity returns a score in [0, 1] for how alike two visible texts are, using the Jaccard index over word 3-grams (shingles). Identical texts score 1; texts with nothing in common score 0.

func VisibleText

func VisibleText(doc []byte) string

VisibleText extracts the human-visible text of an HTML document, one block per line, with whitespace collapsed. The <title> is kept even though it lives in <head>.

Types

type Line

type Line struct {
	Op   Op
	Text string
}

Line is one line of a line-based diff.

func Lines

func Lines(a, b string, context int) []Line

Lines diffs a and b line by line and keeps context unchanged lines around each change. Longer unchanged runs collapse into a single Skip line.

type Op

type Op int

Op is the kind of a diff line.

const (
	Equal Op = iota
	Insert
	Delete
	Skip // marks elided unchanged lines
)

Diff line kinds.

Jump to

Keyboard shortcuts

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