Skip to content

Commit 5ddab20

Browse files
committed
document the usage of metadata object
and add a note about batch performance
1 parent 5aa6b57 commit 5ddab20

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

packages/html-to-text/README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const text = convert(html, {
5050
console.log(text); // Hello World
5151
```
5252

53-
Configure `html-to-text` once for batch processing:
53+
Configure `html-to-text` once for batch processing (recommended for good performance):
5454

5555
```js
5656
const { compile } = require('html-to-text');
@@ -291,6 +291,25 @@ Refer to [generic formatters](https://github.com/html-to-text/node-html-to-text/
291291

292292
Refer to [BlockTextBuilder](https://github.com/html-to-text/node-html-to-text/blob/master/packages/base/src/block-text-builder.js) for available functions and arguments.
293293

294+
#### Custom metadata
295+
296+
If you need to supply extra information about your HTML documents to use in custom formatters - it can be done with the help of metadata object.
297+
298+
It is supplied as an extra argument to the convert function:
299+
300+
```javascript
301+
import { compile, convert } from 'html-to-text';
302+
303+
// for batch use:
304+
const compiledConvert = compile(options);
305+
let text = compiledConvert(html, metadata);
306+
307+
// for single use:
308+
let text = convert(html, options, metadata);
309+
```
310+
311+
And it can be accessed within formatter functions as `builder.metadata`.
312+
294313
#### Call other formatters from a custom formatter
295314

296315
Most of the times this is *not* what you actually need. Most practical problems can be solved with [selectors](#selectors).

0 commit comments

Comments
 (0)