Skip to content

Commit 6336d9b

Browse files
committed
update readme [skip ci]
1 parent fa85d3c commit 6336d9b

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

packages/html-to-text/README.md

+19-13
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,40 @@ Convert a single document:
4343
const { convert } = require('html-to-text');
4444
// There is also an alias to `convert` called `htmlToText`.
4545

46-
const html = '<h1>Hello World</h1>';
47-
const text = convert(html, {
48-
wordwrap: 130
49-
});
46+
const options = {
47+
wordwrap: 130,
48+
// ...
49+
};
50+
const html = '<div>Hello World</div>';
51+
const text = convert(html, options);
5052
console.log(text); // Hello World
5153
```
5254

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):
5456

5557
```js
5658
const { compile } = require('html-to-text');
5759

58-
const convert = compile({
59-
wordwrap: 130
60-
});
60+
const options = {
61+
wordwrap: 130,
62+
// ...
63+
};
64+
const compiledConvert = compile(options); // options passed here
6165

6266
const htmls = [
63-
'<h1>Hello World!</h1>',
64-
'<h1>こんにちは世界!</h1>',
65-
'<h1>Привет, мир!</h1>'
67+
'<div>Hello World!</div>',
68+
'<div>こんにちは世界!</div>',
69+
'<div>Привіт Світ!</div>'
6670
];
67-
const texts = htmls.map(convert);
71+
const texts = htmls.map(compiledConvert);
6872
console.log(texts.join('\n'));
6973
// Hello World!
7074
// こんにちは世界!
71-
// Привет, мир!
75+
// Привіт Світ!
7276
```
7377

78+
Both `convert` and `compiledConvert` can take one more optional argument - [metadata object](#custom-metadata) that can be used by formatters.
79+
7480
### Options
7581

7682
#### General options

0 commit comments

Comments
 (0)