Skip to content

Commit a9fa218

Browse files
authored
Preserve generic types for ReadabilityOptions.serializer (#974)
1 parent 10b7f40 commit a9fa218

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

index.d.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function isProbablyReaderable(
1414
}
1515
): boolean;
1616

17-
export interface ReadabilityOptions {
17+
export interface ReadabilityOptions<T = string> {
1818
/**
1919
* Whether to output debug messages. Defaults to `false`.
2020
*/
@@ -49,13 +49,14 @@ export interface ReadabilityOptions {
4949
*/
5050
keepClasses?: boolean;
5151
/**
52-
* A function that serializes an HTML element into a string.
53-
* Defaults to `el => el.innerHTML`. This is used to get the content
54-
* of the parsed article.
52+
* A function that serializes an HTML element into a string or another representation.
53+
* Defaults to `el => el.innerHTML`. This is used to get the content of the parsed article.
54+
* An identity function (`el => el`) may be useful for returning a DOM element as-is
55+
* for further processing.
5556
* @param el The Node to serialize.
5657
* @returns The HTML string representation of the element's content.
5758
*/
58-
serializer?: (el: Node) => string;
59+
serializer?: (el: Node) => T;
5960
/**
6061
* If `true`, Readability will not attempt to parse or extract
6162
* JSON-LD structured data from the document. Defaults to `false`.
@@ -79,7 +80,7 @@ export interface ReadabilityOptions {
7980
export class Readability<T = string> {
8081
constructor(
8182
document: Document,
82-
options?: ReadabilityOptions
83+
options?: ReadabilityOptions<T>
8384
);
8485

8586
parse(): null | {

0 commit comments

Comments
 (0)