https://github.com/documize/html-diff
Calculate difference between two HTML snippets (in Go)
https://github.com/documize/html-diff
Last synced: over 1 year ago
JSON representation
Calculate difference between two HTML snippets (in Go)
- Host: GitHub
- URL: https://github.com/documize/html-diff
- Owner: documize
- License: mit
- Created: 2016-02-01T16:50:33.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-05-03T14:02:53.000Z (about 10 years ago)
- Last Synced: 2025-01-12T19:35:58.762Z (over 1 year ago)
- Language: HTML
- Homepage:
- Size: 516 KB
- Stars: 35
- Watchers: 8
- Forks: 17
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# html-diff
Calculate difference between two HTML snippets and return those differences as a merged HTML snippet showing the changes.
Usage:
```
var cfg = &htmldiff.Config{
Granularity: 5,
InsertedSpan: []htmldiff.Attribute{{Key: "style", Val: "background-color: palegreen;"}},
DeletedSpan: []htmldiff.Attribute{{Key: "style", Val: "background-color: lightpink;"}},
ReplacedSpan: []htmldiff.Attribute{{Key: "style", Val: "background-color: lightskyblue;"}},
CleanTags: []string{""},
}
res, err := cfg.HTMLdiff([]string{previousHTML, latestHTML})
mergedHTML := res[0]
```

Only deals with body HTML, so no headers, only what is within the body element.
Requires Go1.5+, with vendoring support. Vendors "github.com/mb0/diff", "golang.org/x/net/html" and "golang.org/x/net/html/atom".
Running the tests will create output files in testout/*.html.
For fuzz-testing using https://github.com/dvyukov/go-fuzz , the Fuzz() function is in fuzz.go (as at Feb'16 you need to rename the ```vendor``` directory while you fuzz, and go get the dependencies - an issue with "go/importer", see https://github.com/golang/go/issues/13756).
Pull requests welcome.