You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/html-to-text/README.md
+19-13
Original file line number
Diff line number
Diff line change
@@ -43,34 +43,40 @@ Convert a single document:
43
43
const { convert } =require('html-to-text');
44
44
// There is also an alias to `convert` called `htmlToText`.
45
45
46
-
consthtml='<h1>Hello World</h1>';
47
-
consttext=convert(html, {
48
-
wordwrap:130
49
-
});
46
+
constoptions= {
47
+
wordwrap:130,
48
+
// ...
49
+
};
50
+
consthtml='<div>Hello World</div>';
51
+
consttext=convert(html, options);
50
52
console.log(text); // Hello World
51
53
```
52
54
53
-
Configure `html-to-text` once for batch processing (recommended for good performance):
55
+
Configure `html-to-text` once to convert many documents with the same options (recommended for [good performance](https://github.com/html-to-text/node-html-to-text/issues/265#issuecomment-1337470852) when processing big batches of documents):
54
56
55
57
```js
56
58
const { compile } =require('html-to-text');
57
59
58
-
constconvert=compile({
59
-
wordwrap:130
60
-
});
60
+
constoptions= {
61
+
wordwrap:130,
62
+
// ...
63
+
};
64
+
constcompiledConvert=compile(options); // options passed here
61
65
62
66
consthtmls= [
63
-
'<h1>Hello World!</h1>',
64
-
'<h1>こんにちは世界!</h1>',
65
-
'<h1>Привет, мир!</h1>'
67
+
'<div>Hello World!</div>',
68
+
'<div>こんにちは世界!</div>',
69
+
'<div>Привіт Світ!</div>'
66
70
];
67
-
consttexts=htmls.map(convert);
71
+
consttexts=htmls.map(compiledConvert);
68
72
console.log(texts.join('\n'));
69
73
// Hello World!
70
74
// こんにちは世界!
71
-
//Привет, мир!
75
+
//Привіт Світ!
72
76
```
73
77
78
+
Both `convert` and `compiledConvert` can take one more optional argument - [metadata object](#custom-metadata) that can be used by formatters.
0 commit comments