Skip to content

Commit 0e4bdea

Browse files
committed
docs: document Options, IsProbablyReaderable, and benchmark workflow
README now shows how to pass Options to FromReader, how to use the IsProbablyReaderable pre-check, and how to run the benchmark suite added in 44f1074. The Options example mirrors the godoc fields added in 0bc9d1e so that public API docs and the README stay in sync.
1 parent 02d80ca commit 0e4bdea

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,54 @@ func main() {
102102
}
103103
```
104104

105+
### Options
106+
107+
`FromReader` accepts an optional `*Options` to mirror the upstream parser
108+
configuration knobs:
109+
110+
```go
111+
opts := &readability.Options{
112+
CharThreshold: 500, // skip docs shorter than 500 chars
113+
ClassesToPreserve: []string{"caption", "highlight"}, // extra classes kept during cleanup
114+
KeepClasses: false, // true keeps every class attribute
115+
NbTopCandidates: 5, // candidate pool size during scoring
116+
DisableJSONLD: false, // skip JSON-LD metadata extraction
117+
AllowedVideoRegex: nil, // override built-in video allow list
118+
MaxElemsToParse: 0, // > 0 aborts on huge documents with ErrTooManyElements
119+
}
120+
article, err := readability.FromReader(f, pageURL, opts)
121+
```
122+
123+
When `MaxElemsToParse` is exceeded the call returns `readability.ErrTooManyElements`.
124+
125+
### Probing readerability
126+
127+
For a fast pre-check that does not run the full extractor:
128+
129+
```go
130+
ok, err := readability.IsProbablyReaderable(f)
131+
if err != nil {
132+
log.Fatal(err)
133+
}
134+
if !ok {
135+
return
136+
}
137+
```
138+
139+
`IsProbablyReaderable` accepts an optional `ReaderableOptions` to tune
140+
`MinContentLength` and `MinScore`.
141+
142+
## Benchmarks
143+
144+
A benchmark suite covering small / medium / large / visibility-heavy fixtures
145+
lives in `bench_test.go`:
146+
147+
```sh
148+
go test -bench=. -benchmem -benchtime=2s -run=^$
149+
```
150+
151+
Use the suite as a baseline before / after performance-sensitive changes.
152+
105153
## Upstream Test Data
106154

107155
Compatibility fixtures under `testdata/test-pages` are copied from

0 commit comments

Comments
 (0)