first commit
This commit is contained in:
399
node_modules/html-to-text/CHANGELOG.md
generated
vendored
Normal file
399
node_modules/html-to-text/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,399 @@
|
||||
# Changelog
|
||||
|
||||
## Version 9.0.5
|
||||
|
||||
* `htmlparser2` updated from 8.0.1 to 8.0.2 ([release notes](https://github.com/fb55/htmlparser2/releases)) - this fixes broken parsing in certain situations: [#285](https://github.com/html-to-text/node-html-to-text/issues/285);
|
||||
* `deepmerge` updated from 4.3.0 to 4.3.1 - no functional changes;
|
||||
* added a link to attribute selectors syntax to Readme.
|
||||
|
||||
All commits: [9.0.4...9.0.5](https://github.com/html-to-text/node-html-to-text/compare/9.0.4...9.0.5)
|
||||
|
||||
## Version 9.0.4
|
||||
|
||||
* fixed: `dataTable` formatter was missing some existing cells in incompletely defined tables: [#282](https://github.com/html-to-text/node-html-to-text/issues/282);
|
||||
* updated readme a bit to clarify the usage: [#281](https://github.com/html-to-text/node-html-to-text/issues/281).
|
||||
|
||||
All commits: [9.0.3...9.0.4](https://github.com/html-to-text/node-html-to-text/compare/9.0.3...9.0.4)
|
||||
|
||||
## Version 9.0.3
|
||||
|
||||
* document the usage of metadata object;
|
||||
* explicitly mention `dom-serializer` dependency: [#269](https://github.com/html-to-text/node-html-to-text/issues/269).
|
||||
|
||||
All commits: [9.0.2...9.0.3](https://github.com/html-to-text/node-html-to-text/compare/9.0.2...9.0.3)
|
||||
|
||||
## Version 9.0.2
|
||||
|
||||
* support multi-character code points in `encodeCharacters` option: [#267](https://github.com/html-to-text/node-html-to-text/issues/267).
|
||||
|
||||
All commits: [9.0.1...9.0.2](https://github.com/html-to-text/node-html-to-text/compare/9.0.1...9.0.2)
|
||||
|
||||
## Version 9.0.1
|
||||
|
||||
* fixed a broken link in readme: [#262](https://github.com/html-to-text/node-html-to-text/pull/262);
|
||||
* test and documented the usage of existing formatters from custom formatters in readme: [#263](https://github.com/html-to-text/node-html-to-text/issues/263);
|
||||
* fixed jsdoc comment for `BlockTextBuilder.closeTable`: [#264](https://github.com/html-to-text/node-html-to-text/issues/264);
|
||||
* added missing entry in the 9.0.0 changelog below regarding `BlockTextBuilder.closeTable`.
|
||||
|
||||
All commits: [9.0.0...9.0.1](https://github.com/html-to-text/node-html-to-text/compare/9.0.0...9.0.1)
|
||||
|
||||
## Version 9.0.0
|
||||
|
||||
All commits: [8.2.1...9.0.0](https://github.com/html-to-text/node-html-to-text/compare/8.2.1...9.0.0)
|
||||
|
||||
Version 9 roadmap: [#240](https://github.com/html-to-text/node-html-to-text/issues/240)
|
||||
|
||||
Request for comments: [#261 \[RFC\] Naming issue](https://github.com/html-to-text/node-html-to-text/discussions/261) - please take a look and share opinions while you're here
|
||||
|
||||
### Node version
|
||||
|
||||
Required Node version is now >=14.
|
||||
|
||||
### CommonJS and ES Module
|
||||
|
||||
Package now provides `cjs` and `mjs` exports.
|
||||
|
||||
### CLI is no longer built in
|
||||
|
||||
If you use CLI then install [that package](https://github.com/html-to-text/node-html-to-text/tree/master/packages/html-to-text-cli/) instead.
|
||||
|
||||
The new package uses new arg parser [aspargvs](https://github.com/mxxii/aspargvs) instead of minimist in order to deal with the vast options space of `html-to-text`.
|
||||
|
||||
### Dependency updates
|
||||
|
||||
* `htmlparser2` updated from 6.1.0 to 8.0.1 ([Release notes](https://github.com/fb55/htmlparser2/releases));
|
||||
* `he` dependency is removed. It was needed at the time it was introduced, apparently, but at this point `htmlparser2` seems to do a better job itself.
|
||||
|
||||
### Removed features
|
||||
|
||||
* Options deprecated in version 6 are now removed;
|
||||
* `decodeOptions` section removed with `he` dependency;
|
||||
* `fromString` method removed;
|
||||
* deprecated positional arguments in `BlockTextBuilder` methods are now removed.
|
||||
|
||||
Refer to README for [migration instructions](https://github.com/html-to-text/node-html-to-text/tree/master/packages/html-to-text#deprecated-or-removed-options).
|
||||
|
||||
### New options
|
||||
|
||||
* `decodeEntities` - controls whether HTML entities found in the input HTML should be decoded or left as is in the output text;
|
||||
* `encodeCharacters` - a dictionary with characters that should be replaced in the output text and corresponding escape sequences.
|
||||
|
||||
### New built-in formatters
|
||||
|
||||
New generic formatters `blockString`, `blockTag`, `blockHtml`, `inlineString`, `inlineSurround`, `inlineTag`, `inlineHtml` cover some common usage scenarios such as [#231](https://github.com/html-to-text/node-html-to-text/issues/231).
|
||||
|
||||
### Changes to existing built-in formatters
|
||||
|
||||
* `anchor` and `image` got `pathRewrite` option;
|
||||
* `dataTable` formatter allows zero `colSpacing`.
|
||||
|
||||
### Improvements for writing custom formatters
|
||||
|
||||
* Some logic for making lists is moved to BlockTextBuilder and can be reused for custom lists (`openList`, `openListItem`, `closeListItem`, `closeList`). Addresses [#238](https://github.com/html-to-text/node-html-to-text/issues/238);
|
||||
* `startNoWrap`, `stopNoWrap` - allows to keep local inline content in a single line regardless of wrapping options;
|
||||
* `addLiteral` - it is like `addInline` but circumvents most of the text processing logic. This should be preferred when inserting markup elements;
|
||||
* It is now possible to provide a metadata object along with the HTML string to convert. Metadata object is available for custom formatters via `builder.metadata`. This allows to compile the converter once and still being able to supply per-document data. Metadata object is supplied as the last optional argument to `convert` function and the function returned by `compile` function;
|
||||
* Breaking change for those who dare to write their own table formatter (in case there is anyone) - `closeTable` function got a required property in the options object - `tableToString` function, and previously existed `colSpacing` and `rowSpacing` are removed (now a responsibility of the `tableToString` function).
|
||||
|
||||
### Other
|
||||
|
||||
* Fix deprecated `tags` option support. Addresses [#253](https://github.com/html-to-text/node-html-to-text/issues/253).
|
||||
|
||||
|
||||
----
|
||||
|
||||
## Version 8.2.1
|
||||
|
||||
No changes in published package. Bumped dev dependencies and regenerated `package-lock.json`.
|
||||
|
||||
## Version 8.2.0
|
||||
|
||||
Fix for the issue [#249](https://github.com/html-to-text/node-html-to-text/issues/249) and possibly other obscure issues when some selector options are ignored. `options.selectors` array was not fully processed before.
|
||||
|
||||
## Version 8.1.1
|
||||
|
||||
Bump `minimist` dependency, regenerate `package-lock.json`.
|
||||
|
||||
## Version 8.1.0
|
||||
|
||||
* Fix for too many newlines in certain cases when `preserveNewlines` option is used. Addresses [#232](https://github.com/html-to-text/node-html-to-text/issues/232);
|
||||
* Link and image formatters now have a `linkBrackets` option - it accepts an array of two strings (default: `['[', ']']`) or `false` to remove the brackets. Addresses [#236](https://github.com/html-to-text/node-html-to-text/issues/236);
|
||||
* `noLinkBrackets` formatters option is now deprecated.
|
||||
|
||||
All commits: [8.0.0...8.1.0](https://github.com/html-to-text/node-html-to-text/compare/8.0.0...8.1.0)
|
||||
|
||||
## Version 8.0.0
|
||||
|
||||
All commits: [7.1.1...8.0.0](https://github.com/html-to-text/node-html-to-text/compare/7.1.1...8.0.0)
|
||||
|
||||
Version 8 roadmap issue: [#228](https://github.com/html-to-text/node-html-to-text/issues/228)
|
||||
|
||||
### Selectors
|
||||
|
||||
The main focus of this version. Addresses the most demanded user requests ([#159](https://github.com/html-to-text/node-html-to-text/issues/159), [#179](https://github.com/html-to-text/node-html-to-text/issues/179), partially [#143](https://github.com/html-to-text/node-html-to-text/issues/143)).
|
||||
|
||||
It is now possible to specify formatting options or assign custom formatters not only by tag names but by almost any selectors.
|
||||
|
||||
See the README [Selectors](https://github.com/html-to-text/node-html-to-text#selectors) section for details.
|
||||
|
||||
Note: The new `selectors` option is an array, in contrast to the `tags` option introduced in version 6 (and now deprecated). Selectors have to have a well defined order and object properties is not a right tool for that.
|
||||
|
||||
Two new packages were created to enable this feature - [parseley](https://github.com/mxxii/parseley) and [selderee](https://github.com/mxxii/selderee).
|
||||
|
||||
### Base elements
|
||||
|
||||
The same selectors implementation is used now to narrow down the conversion to specific HTML DOM fragments. Addresses [#96](https://github.com/html-to-text/node-html-to-text/issues/96). (Previous implementation had more limited selectors format.)
|
||||
|
||||
BREAKING CHANGE: All outermost elements matching provided selectors will be present in the output (previously it was only the first match for each selector). Addresses [#215](https://github.com/html-to-text/node-html-to-text/issues/215).
|
||||
|
||||
`limits.maxBaseElements` can be used when you only need a fixed number of base elements and would like to avoid checking the rest of the source HTML document.
|
||||
|
||||
Base elements can be arranged in output text in the order of matched selectors (default, to keep it closer to the old implementation) or in the order of appearance in source HTML document.
|
||||
|
||||
BREAKING CHANGE: previous implementation was treating id selectors in the same way as class selectors (could match `<foo id="a b">` with `foo#a` selector). New implementation is closer to the spec and doesn't expect multiple ids on an element. You can achieve the old behavior with `foo[id~=a]` selector in case you rely on it for some poorly formatted documents (note that it has different specificity though).
|
||||
|
||||
### Batch processing
|
||||
|
||||
Since options preprocessing is getting more involved with selectors compilation, it seemed reasonable to break the single `htmlToText()` function into compilation and convertation steps. It might provide some performance benefits in client code.
|
||||
|
||||
* new function `compile(options)` returns a function of a single argument (html string);
|
||||
* `htmlToText(html, options)` is now an alias to `convert(html, options)` function and works as before.
|
||||
|
||||
### Deprecated options
|
||||
|
||||
* `baseElement`;
|
||||
* `returnDomByDefault`;
|
||||
* `tables`;
|
||||
* `tags`.
|
||||
|
||||
Refer to README for [migration instructions](https://github.com/html-to-text/node-html-to-text#deprecated-or-removed-options).
|
||||
|
||||
No previously deprecated stuff is removed in this version. Significant cleanup is planned for version 9 instead.
|
||||
|
||||
----
|
||||
|
||||
## Version ~~7.1.2~~ 7.1.3
|
||||
|
||||
Bump `minimist` dependency and dev dependencies, regenerate `package-lock.json`.
|
||||
|
||||
## Version 7.1.1
|
||||
|
||||
Regenerate `package-lock.json`.
|
||||
|
||||
## Version 7.1.0
|
||||
|
||||
### Dependency updates
|
||||
|
||||
* `htmlparser2` updated from 6.0.0 to 6.1.0 ([Release notes](https://github.com/fb55/htmlparser2/releases));
|
||||
* dev dependencies are bumped.
|
||||
|
||||
## Version 7.0.0
|
||||
|
||||
### Node version
|
||||
|
||||
Required Node version is now >=10.23.2.
|
||||
|
||||
### Dependency updates
|
||||
|
||||
* `lodash` dependency is removed;
|
||||
* `htmlparser2` updated from 4.1.0 to 6.0.0 ([Release notes](https://github.com/fb55/htmlparser2/releases), also [domhandler](https://github.com/fb55/domhandler/releases/tag/v4.0.0)). There is a slim chance you can run into some differences in case you're relying on it heavily in your custom formatters;
|
||||
* dev dependencies are bumped.
|
||||
|
||||
### Custom formatters API change
|
||||
|
||||
[BlockTextBuilder](https://github.com/html-to-text/node-html-to-text/blob/master/lib/block-text-builder.js) methods now accept option objects for optional arguments. This improves client code readability and allows to introduce extra options with ease. It will see some use in future updates.
|
||||
|
||||
Positional arguments introduced in version 6.0.0 are now deprecated. Formatters written for the version 6.0.0 should keep working for now but the compatibility layer is rather inconvenient and will be removed with the next major version.
|
||||
|
||||
See the commit [f50f10f](https://github.com/html-to-text/node-html-to-text/commit/f50f10f54cf814efb2f7633d9d377ba7eadeaf1e). Changes in `lib/formatter.js` file are illustrative for how to migrate to the new API.
|
||||
|
||||
### And more
|
||||
|
||||
* Bunch of documentation and test updates.
|
||||
|
||||
All commits: [6.0.0...7.0.0](https://github.com/html-to-text/node-html-to-text/compare/6.0.0...7.0.0)
|
||||
|
||||
Version 7 roadmap issue: [#222](https://github.com/html-to-text/node-html-to-text/issues/222)
|
||||
|
||||
----
|
||||
|
||||
## Version 6.0.0
|
||||
|
||||
This is a major update. No code left untouched. While the goal was to keep as much compatibility as possible, some client-facing changes were unavoidable.
|
||||
|
||||
### fromString() is deprecated in favor of htmlToText()
|
||||
|
||||
Since the library has the only exported function, it is now self-titled.
|
||||
|
||||
### Inline and block-level tags, HTML whitespace
|
||||
|
||||
Formatting code was rewritten almost entirely to make it aware of block-level tags and to handle HTML whitespace properly. One of popular requests was to support divs, and it is here now, after a lot of effort.
|
||||
|
||||
### Options reorganized
|
||||
|
||||
Options are reorganized to make room for some extra format options while making everything more structured. Now tag-specific options live within that tag configuration.
|
||||
|
||||
For the majority of changed options there is a compatibility layer that will remain until next major release. But you are encouraged to explore new options since they provide a bit more flexibility.
|
||||
|
||||
### Custom formatters are different now
|
||||
|
||||
Because formatters are integral part of the formatting code (as the name suggests), it wasn't possible to provide a compatibility layer.
|
||||
|
||||
Please refer to the Readme to see how things are wired now, in case you were using them for anything other than dealing with the lack of block-level tags support.
|
||||
|
||||
### Tables support was improved
|
||||
|
||||
Cells can make use of extra space with colspan and rowspan attributes. Max column width is defined separately from global wordwrap limit.
|
||||
|
||||
### Limits
|
||||
|
||||
Multiple options to cut content in large HTML documents.
|
||||
|
||||
By default, any input longer than 16 million characters will be truncated.
|
||||
|
||||
### Node and dependencies
|
||||
|
||||
Required Node version is now >=8.10.0.
|
||||
|
||||
Dependency versions are bumped.
|
||||
|
||||
### Repository is moved to it's own organization
|
||||
|
||||
[https://github.com/html-to-text/node-html-to-text](https://github.com/html-to-text/node-html-to-text) is the new home.
|
||||
|
||||
GitHub should handle all redirects from the old url, so it shouldn't break anything, even if you have a local fork pointing at the old origin. But it is still a good idea to [update](https://docs.github.com/en/free-pro-team@latest/github/using-git/changing-a-remotes-url) the url.
|
||||
|
||||
### And more
|
||||
|
||||
Version 6 roadmap issue: [#200](https://github.com/html-to-text/node-html-to-text/issues/200)
|
||||
|
||||
----
|
||||
|
||||
## Version 5.1.1
|
||||
|
||||
* `preserveNewLines` whitespace issue fixed [#162](https://github.com/html-to-text/node-html-to-text/pull/162)
|
||||
|
||||
## Version 5.1.0
|
||||
|
||||
* Hard-coded CLI options removed [#173](https://github.com/html-to-text/node-html-to-text/pull/173)
|
||||
|
||||
## Version 5.0.0
|
||||
|
||||
### BREAKING CHANGES
|
||||
|
||||
#### fromFile removed
|
||||
|
||||
The function `fromFile` is removed. It was the main reason `html-to-text` could not be used in the browser [#164](https://github.com/html-to-text/node-html-to-text/pull/164).
|
||||
|
||||
You can get the `fromFile` functionality back by using the following code
|
||||
|
||||
```js
|
||||
const fs = require('fs');
|
||||
const { fromString } = require('html-to-text');
|
||||
|
||||
// Callback version
|
||||
const fromFile = (file, options, callback) => {
|
||||
if (!callback) {
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
fs.readFile(file, 'utf8', (err, str) => {
|
||||
if (err) return callback(err);
|
||||
callback(null, fromString(str, options));
|
||||
});
|
||||
};
|
||||
|
||||
// Promise version
|
||||
const fromFile = (file, option) => fs.promises.readFile(file, 'utf8').then(html => fromString(html, options));
|
||||
|
||||
// Sync version
|
||||
const fromFileSync = (file, options) => fromString(fs.readFileSync(file, 'utf8'), options);
|
||||
```
|
||||
|
||||
#### Supported NodeJS Versions
|
||||
|
||||
Node versions < 6 are no longer supported.
|
||||
|
||||
----
|
||||
|
||||
## Version 4.0.0
|
||||
|
||||
* Support dropped for node version < 4.
|
||||
* New option `unorderedListItemPrefix` added.
|
||||
* HTML entities in links are not supported.
|
||||
|
||||
----
|
||||
|
||||
## Version 3.3.0
|
||||
|
||||
* Ability to pass custom formatting via the `format` option #128
|
||||
* Enhanced support for alpha ordered list types added #123
|
||||
|
||||
## Version 3.2.0
|
||||
|
||||
* Basic support for alpha ordered list types added #122
|
||||
* This includes support for the `ol` type values `1`, `a` and `A`
|
||||
|
||||
## Version 3.1.0
|
||||
|
||||
* Support for the ordered list start attribute added #117
|
||||
* Option to format paragraph with single new line #112
|
||||
* `noLinksBrackets` options added #119
|
||||
|
||||
## Version 3.0.0
|
||||
|
||||
* Switched from `htmlparser` to `htmlparser2` #113
|
||||
* Treat non-numeric colspans as zero and handle them gracefully #105
|
||||
|
||||
----
|
||||
|
||||
## Version 2.1.1
|
||||
|
||||
* Extra space problem fixed. #88
|
||||
|
||||
## Version 2.1.0
|
||||
|
||||
* New option to disable `uppercaseHeadings` added. #86
|
||||
* Starting point of html to text conversion can now be defined in the options via the `baseElement` option. #83
|
||||
* Support for long words added. The behaviour can be configured via the `longWordSplit` option. #83
|
||||
|
||||
## Version 2.0.0
|
||||
|
||||
* Unicode support added. #81
|
||||
* New option `decodeOptions` added.
|
||||
* Dependencies updated.
|
||||
|
||||
Breaking Changes:
|
||||
|
||||
* Minimum node version increased to >=0.10.0
|
||||
|
||||
----
|
||||
|
||||
## Version 1.6.2
|
||||
|
||||
* Fixed: correctly handle HTML entities for images #82
|
||||
|
||||
## Version 1.6.1
|
||||
|
||||
* Fixed: using --tables=true doesn't produce the expected results. #80
|
||||
|
||||
## Version 1.6.0
|
||||
|
||||
* Preserve newlines in text feature added #75
|
||||
|
||||
## Version 1.5.1
|
||||
|
||||
* Support for h5 and h6 tags added #74
|
||||
|
||||
## Version 1.5.0
|
||||
|
||||
* Entity regex is now less greedy #69 #70
|
||||
|
||||
## Version 1.4.0
|
||||
|
||||
* Uppercase tag processing added. Table center support added. #56
|
||||
* Unused dependencies removed.
|
||||
|
||||
## Version 1.3.2
|
||||
|
||||
* Support Node 4 engine #64
|
25
node_modules/html-to-text/LICENSE
generated
vendored
Normal file
25
node_modules/html-to-text/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
MIT License
|
||||
|
||||
Portions Copyright (c) 2012-2019 werk85 <malte@werk85.de>
|
||||
Portions Copyright (c) 2020-2022 KillyMXI <killy@mxii.eu.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
361
node_modules/html-to-text/README.md
generated
vendored
Normal file
361
node_modules/html-to-text/README.md
generated
vendored
Normal file
@@ -0,0 +1,361 @@
|
||||
# html-to-text
|
||||
|
||||
[](https://github.com/html-to-text/node-html-to-text/actions/workflows/lint.yml)
|
||||
[](https://github.com/html-to-text/node-html-to-text/actions/workflows/test.yml)
|
||||
[](https://github.com/html-to-text/node-html-to-text/blob/master/LICENSE)
|
||||
[](https://www.npmjs.com/package/html-to-text)
|
||||
[](https://www.npmjs.com/package/html-to-text)
|
||||
|
||||
Advanced converter that parses HTML and returns beautiful text.
|
||||
|
||||
## Features
|
||||
|
||||
* Inline and block-level tags.
|
||||
* Tables with colspans and rowspans.
|
||||
* Links with both text and href.
|
||||
* Word wrapping.
|
||||
* Unicode support.
|
||||
* Plenty of customization options.
|
||||
|
||||
## Changelog
|
||||
|
||||
Available here: [CHANGELOG.md](https://github.com/html-to-text/node-html-to-text/blob/master/packages/html-to-text/CHANGELOG.md)
|
||||
|
||||
Version 6 contains a ton of changes, so it worth to take a look at the full changelog.
|
||||
|
||||
Version 7 contains an important change for custom formatters.
|
||||
|
||||
Version 8 brings the selectors support to greatly increase the flexibility but that also changes some things introduced in version 6. Base element(s) selection also got important changes.
|
||||
|
||||
Version 9 drops a lot of previously deprecated options, introduces some new formatters and new capabilities for custom formatters. Now a dual-mode package (cjs and esm). CLI is moved to a [separate package](https://github.com/html-to-text/node-html-to-text/tree/master/packages/html-to-text-cli/).
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
npm install html-to-text
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Convert a single document:
|
||||
|
||||
```js
|
||||
const { convert } = require('html-to-text');
|
||||
// There is also an alias to `convert` called `htmlToText`.
|
||||
|
||||
const options = {
|
||||
wordwrap: 130,
|
||||
// ...
|
||||
};
|
||||
const html = '<div>Hello World</div>';
|
||||
const text = convert(html, options);
|
||||
console.log(text); // Hello World
|
||||
```
|
||||
|
||||
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):
|
||||
|
||||
```js
|
||||
const { compile } = require('html-to-text');
|
||||
|
||||
const options = {
|
||||
wordwrap: 130,
|
||||
// ...
|
||||
};
|
||||
const compiledConvert = compile(options); // options passed here
|
||||
|
||||
const htmls = [
|
||||
'<div>Hello World!</div>',
|
||||
'<div>こんにちは世界!</div>',
|
||||
'<div>Привіт Світ!</div>'
|
||||
];
|
||||
const texts = htmls.map(compiledConvert);
|
||||
console.log(texts.join('\n'));
|
||||
// Hello World!
|
||||
// こんにちは世界!
|
||||
// Привіт Світ!
|
||||
```
|
||||
|
||||
Both `convert` and `compiledConvert` can take one more optional argument - [metadata object](#custom-metadata) that can be used by formatters.
|
||||
|
||||
### Options
|
||||
|
||||
#### General options
|
||||
|
||||
Option | Default | Description
|
||||
----------------------- | ------------ | -----------
|
||||
`baseElements` | | Describes which parts of the input document have to be converted and present in the output text, and in what order.
|
||||
`baseElements.selectors` | `['body']` | Elements matching any of provided selectors will be processed and included in the output text, with all inner content.<br/>Refer to [Supported selectors](#supported-selectors) section below.
|
||||
`baseElements.orderBy` | `'selectors'` | `'selectors'` - arrange base elements in the same order as `baseElements.selectors` array;<br/>`'occurrence'` - arrange base elements in the order they are found in the input document.
|
||||
`baseElements.returnDomByDefault` | `true` | Convert the entire document if none of provided selectors match.
|
||||
`decodeEntities` | `true` | Decode HTML entities found in the input HTML if `true`. Otherwise preserve in output text.
|
||||
`encodeCharacters` | `{}` | A dictionary with characters that should be replaced in the output text and corresponding escape sequences.
|
||||
`formatters` | `{}` | An object with custom formatting functions for specific elements (see [Override formatting](#override-formatting) section below).
|
||||
`limits` | | Describes how to limit the output text in case of large HTML documents.
|
||||
`limits.ellipsis` | `'...'` | A string to insert in place of skipped content.
|
||||
`limits.maxBaseElements` | `undefined` | Stop looking for more base elements after reaching this amount. Unlimited if undefined.
|
||||
`limits.maxChildNodes` | `undefined` | Maximum number of child nodes of a single node to be added to the output. Unlimited if undefined.
|
||||
`limits.maxDepth` | `undefined` | Stop looking for nodes to add to the output below this depth in the DOM tree. Unlimited if undefined.
|
||||
`limits.maxInputLength` | `16_777_216` | If the input string is longer than this value - it will be truncated and a message will be sent to `stderr`. Ellipsis is not used in this case. Unlimited if undefined.
|
||||
`longWordSplit` | | Describes how to wrap long words.
|
||||
`longWordSplit.wrapCharacters` | `[]` | An array containing the characters that may be wrapped on. Checked in order, search stops once line length requirement can be met.
|
||||
`longWordSplit.forceWrapOnLimit` | `false` | Break long words at the line length limit in case no better wrap opportunities found.
|
||||
`preserveNewlines` | `false` | By default, any newlines `\n` from the input HTML are collapsed into space as any other HTML whitespace characters. If `true`, these newlines will be preserved in the output. This is only useful when input HTML carries some plain text formatting instead of proper tags.
|
||||
`selectors` | `[]` | Describes how different HTML elements should be formatted. See [Selectors](#selectors) section below.
|
||||
`whitespaceCharacters` | `' \t\r\n\f\u200b'` | A string of characters that are recognized as HTML whitespace. Default value uses the set of characters defined in [HTML4 standard](https://www.w3.org/TR/html4/struct/text.html#h-9.1). (It includes Zero-width space compared to [living standard](https://infra.spec.whatwg.org#ascii-whitespace).)
|
||||
`wordwrap` | `80` | After how many chars a line break should follow.<br/>Set to `null` or `false` to disable word-wrapping.
|
||||
|
||||
#### Deprecated or removed options
|
||||
|
||||
Old option | Depr. | Rem. | Instead use
|
||||
-------------------------- | --- | ----- | -----------------
|
||||
`baseElement` | 8.0 | | `baseElements: { selectors: [ 'body' ] }`
|
||||
`decodeOptions` | | 9.0 | Entity decoding is now handled by [htmlparser2](https://github.com/fb55/htmlparser2) itself and [entities](https://github.com/fb55/entities) internally. No user-configurable parts compared to [he](https://github.com/mathiasbynens/he) besides boolean `decodeEntities`.
|
||||
`format` | | 6.0 | The way formatters are written has changed completely. New formatters have to be added to the `formatters` option, old ones can not be reused without rewrite. See [new instructions](#override-formatting) below.
|
||||
`hideLinkHrefIfSameAsText` | 6.0 | 9.0 | `selectors: [ { selector: 'a', options: { hideLinkHrefIfSameAsText: true } } ]`
|
||||
`ignoreHref` | 6.0 | 9.0 | `selectors: [ { selector: 'a', options: { ignoreHref: true } } ]`
|
||||
`ignoreImage` | 6.0 | 9.0 | `selectors: [ { selector: 'img', format: 'skip' } ]`
|
||||
`linkHrefBaseUrl` | 6.0 | 9.0 | `selectors: [`<br/>`{ selector: 'a', options: { baseUrl: 'https://example.com' } },`<br/>`{ selector: 'img', options: { baseUrl: 'https://example.com' } }`<br/>`]`
|
||||
`noAnchorUrl` | 6.0 | 9.0 | `selectors: [ { selector: 'a', options: { noAnchorUrl: true } } ]`
|
||||
`noLinkBrackets` | 6.0 | 9.0 | `selectors: [ { selector: 'a', options: { linkBrackets: false } } ]`
|
||||
`returnDomByDefault` | 8.0 | | `baseElements: { returnDomByDefault: true }`
|
||||
`singleNewLineParagraphs` | 6.0 | 9.0 | `selectors: [`<br/>`{ selector: 'p', options: { leadingLineBreaks: 1, trailingLineBreaks: 1 } },`<br/>`{ selector: 'pre', options: { leadingLineBreaks: 1, trailingLineBreaks: 1 } }`<br/>`]`
|
||||
`tables` | 8.0 | | `selectors: [ { selector: 'table.class#id', format: 'dataTable' } ]`
|
||||
`tags` | 8.0 | | See [Selectors](#selectors) section below.
|
||||
`unorderedListItemPrefix` | 6.0 | 9.0 | `selectors: [ { selector: 'ul', options: { itemPrefix: ' * ' } } ]`
|
||||
`uppercaseHeadings` | 6.0 | 9.0 | `selectors: [`<br/>`{ selector: 'h1', options: { uppercase: false } },`<br/>`...`<br/>`{ selector: 'table', options: { uppercaseHeaderCells: false } }`<br/>`]`
|
||||
|
||||
Other things removed:
|
||||
|
||||
* `fromString` method - use `convert` or `htmlToText` instead;
|
||||
* positional arguments in `BlockTextBuilder` methods - pass option objects instead.
|
||||
|
||||
#### Selectors
|
||||
|
||||
Some example:
|
||||
|
||||
```javascript
|
||||
const { convert } = require('html-to-text');
|
||||
|
||||
const html = '<a href="/page.html">Page</a><a href="!#" class="button">Action</a>';
|
||||
const text = convert(html, {
|
||||
selectors: [
|
||||
{ selector: 'a', options: { baseUrl: 'https://example.com' } },
|
||||
{ selector: 'a.button', format: 'skip' }
|
||||
]
|
||||
});
|
||||
console.log(text); // Page [https://example.com/page.html]
|
||||
```
|
||||
|
||||
Selectors array is our loose approximation of a stylesheet.
|
||||
|
||||
* highest [specificity](https://www.w3.org/TR/selectors/#specificity) selector is used when there are multiple matches;
|
||||
* the last selector is used when there are multiple matches of equal specificity;
|
||||
* all entries with the same selector value are merged (recursively) at the compile stage, in such way so the last defined properties a kept and the relative order of unique selectors is kept;
|
||||
* user-defined entries are appended after [predefined entries](#predefined-formatters);
|
||||
* Every unique selector must have `format` value specified (at least once);
|
||||
* unlike in CSS, values from different matched selectors are NOT merged at the convert stage. Single best match is used instead (that is the last one of those with highest specificity).
|
||||
|
||||
To achieve the best performance when checking each DOM element against provided selectors, they are compiled into a decision tree. But it is also important how you choose selectors. For example, `div#id` is much better than `#id` - the former will only check divs for the id while the latter has to check every element in the DOM.
|
||||
|
||||
##### Supported selectors
|
||||
|
||||
`html-to-text` relies on [parseley](https://github.com/mxxii/parseley) and [selderee](https://github.com/mxxii/selderee) packages for selectors support.
|
||||
|
||||
Following selectors can be used in any combinations:
|
||||
|
||||
* `*` - universal selector;
|
||||
* `div` - tag name;
|
||||
* `.foo` - class name;
|
||||
* `#bar` - id;
|
||||
* `[baz]` - attribute presence;
|
||||
* `[baz=buzz]` - attribute value (with any operators and also quotes and case sensitivity modifiers - [syntax](https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors#syntax));
|
||||
* `+` and `>` combinators (other combinators are not supported).
|
||||
|
||||
You can match `<p style="...; display:INLINE; ...">...</p>` with `p[style*="display:inline"i]` for example.
|
||||
|
||||
##### Predefined formatters
|
||||
|
||||
Following selectors have a formatter specified as a part of the default configuration. Everything can be overridden, but you don't have to repeat the `format` or options that you don't want to override. (But keep in mind this is only true for the same selector. There is no connection between different selectors.)
|
||||
|
||||
Selector | Default format | Notes
|
||||
------------- | ------------------- | -----
|
||||
`*` | `inline` | Universal selector.
|
||||
`a` | `anchor` |
|
||||
`article` | `block` |
|
||||
`aside` | `block` |
|
||||
`blockquote` | `blockquote` |
|
||||
`br` | `lineBreak` |
|
||||
`div` | `block` |
|
||||
`footer` | `block` |
|
||||
`form` | `block` |
|
||||
`h1` | `heading` |
|
||||
`h2` | `heading` |
|
||||
`h3` | `heading` |
|
||||
`h4` | `heading` |
|
||||
`h5` | `heading` |
|
||||
`h6` | `heading` |
|
||||
`header` | `block` |
|
||||
`hr` | `horizontalLine` |
|
||||
`img` | `image` |
|
||||
`main` | `block` |
|
||||
`nav` | `block` |
|
||||
`ol` | `orderedList` |
|
||||
`p` | `paragraph` |
|
||||
`pre` | `pre` |
|
||||
`table` | `table` | Equivalent to `block`. Use `dataTable` instead for tabular data.
|
||||
`ul` | `unorderedList` |
|
||||
`wbr` | `wbr` |
|
||||
|
||||
More formatters also available for use:
|
||||
|
||||
Format | Description
|
||||
---------------- | -----------
|
||||
`dataTable` | For visually-accurate tables. Note that this might be not search-friendly (output text will look like gibberish to a machine when there is any wrapped cell contents) and also better to be avoided for tables used as a page layout tool.
|
||||
`skip` | Skips the given tag with it's contents without printing anything.
|
||||
`blockString` | Insert a block with the given string literal (`formatOptions.string`) instead of the tag.
|
||||
`blockTag` | Render an element as HTML block bag, convert it's contents to text.
|
||||
`blockHtml` | Render an element with all it's children as HTML block.
|
||||
`inlineString` | Insert the given string literal (`formatOptions.string`) inline instead of the tag.
|
||||
`inlineSurround` | Render inline element wrapped with given strings (`formatOptions.prefix` and `formatOptions.suffix`).
|
||||
`inlineTag` | Render an element as inline HTML tag, convert it's contents to text.
|
||||
`inlineHtml` | Render an element with all it's children as inline HTML.
|
||||
|
||||
##### Format options
|
||||
|
||||
Following options are available for built-in formatters.
|
||||
|
||||
Option | Default | Applies to | Description
|
||||
------------------- | ----------- | ------------------ | -----------
|
||||
`leadingLineBreaks` | `1`, `2` or `3` | all block-level formatters | Number of line breaks to separate previous block from this one.<br/>Note that N+1 line breaks are needed to make N empty lines.
|
||||
`trailingLineBreaks` | `1` or `2` | all block-level formatters | Number of line breaks to separate this block from the next one.<br/>Note that N+1 line breaks are needed to make N empty lines.
|
||||
`baseUrl` | `null` | `anchor`, `image` | Server host for link `href` attributes and image `src` attributes relative to the root (the ones that start with `/`).<br/>For example, with `baseUrl = 'http://asdf.com'` and `<a href='/dir/subdir'>...</a>` the link in the text will be `http://asdf.com/dir/subdir`.
|
||||
`linkBrackets` | `['[', ']']` | `anchor`, `image` | Surround links with these brackets.<br/>Set to `false` or `['', '']` to disable.
|
||||
`pathRewrite` | `undefined` | `anchor`, `image` | A function to rewrite link `href` attributes and image `src` attributes. Optional second argument is the metadata object.<br/>Applied before `baseUrl`.
|
||||
`hideLinkHrefIfSameAsText` | `false` | `anchor` | By default links are translated in the following way:<br/>`<a href='link'>text</a>` => becomes => `text [link]`.<br/>If this option is set to `true` and `link` and `text` are the same, `[link]` will be omitted and only `text` will be present.
|
||||
`ignoreHref` | `false` | `anchor` | Ignore all links. Only process internal text of anchor tags.
|
||||
`noAnchorUrl` | `true` | `anchor` | Ignore anchor links (where `href='#...'`).
|
||||
`itemPrefix` | `' * '` | `unorderedList` | String prefix for each list item.
|
||||
`uppercase` | `true` | `heading` | By default, headings (`<h1>`, `<h2>`, etc) are uppercased.<br/>Set this to `false` to leave headings as they are.
|
||||
`length` | `undefined` | `horizontalLine` | Length of the line. If undefined then `wordwrap` value is used. Falls back to 40 if that's also disabled.
|
||||
`trimEmptyLines` | `true` | `blockquote` | Trim empty lines from blockquote.<br/>While empty lines should be preserved in HTML, space-saving behavior is chosen as default for convenience.
|
||||
`uppercaseHeaderCells` | `true` | `dataTable` | By default, heading cells (`<th>`) are uppercased.<br/>Set this to `false` to leave heading cells as they are.
|
||||
`maxColumnWidth` | `60` | `dataTable` | Data table cell content will be wrapped to fit this width instead of global `wordwrap` limit.<br/>Set this to `undefined` in order to fall back to `wordwrap` limit.
|
||||
`colSpacing` | `3` | `dataTable` | Number of spaces between data table columns.
|
||||
`rowSpacing` | `0` | `dataTable` | Number of empty lines between data table rows.
|
||||
`string` | `''` | `blockString`, `inlineString` | A string to be inserted in place of a tag.
|
||||
`prefix` | `''` | `inlineSurround` | String prefix to be inserted before inline tag contents.
|
||||
`suffix` | `''` | `inlineSurround` | String suffix to be inserted after inline tag contents.
|
||||
|
||||
##### Deprecated format options
|
||||
|
||||
Old option | Applies to | Depr. | Rem. | Instead use
|
||||
------------------- | ------------------ | ----- | ---- | ---------------------
|
||||
`noLinkBrackets` | `anchor` | 8.1 | | `linkBrackets: false`
|
||||
|
||||
### Override formatting
|
||||
|
||||
`formatters` option is an object that holds formatting functions. They can be assigned to format different elements in the `selectors` array.
|
||||
|
||||
Each formatter is a function of four arguments that returns nothing. Arguments are:
|
||||
|
||||
* `elem` - the HTML element to be processed by this formatter;
|
||||
* `walk` - recursive function to process the children of this element. Called as `walk(elem.children, builder)`;
|
||||
* `builder` - [BlockTextBuilder](https://github.com/html-to-text/node-html-to-text/blob/master/packages/base/src/block-text-builder.js) object. Manipulate this object state to build the output text;
|
||||
* `formatOptions` - options that are specified for a tag, along with this formatter (Note: if you need general html-to-text [options](#general-options) - they are accessible via `builder.options`).
|
||||
|
||||
Custom formatter example:
|
||||
|
||||
```javascript
|
||||
const { convert } = require('html-to-text');
|
||||
|
||||
const html = '<foo>Hello World</foo>';
|
||||
const text = convert(html, {
|
||||
formatters: {
|
||||
// Create a formatter.
|
||||
'fooBlockFormatter': function (elem, walk, builder, formatOptions) {
|
||||
builder.openBlock({ leadingLineBreaks: formatOptions.leadingLineBreaks || 1 });
|
||||
walk(elem.children, builder);
|
||||
builder.addInline('!');
|
||||
builder.closeBlock({ trailingLineBreaks: formatOptions.trailingLineBreaks || 1 });
|
||||
}
|
||||
},
|
||||
selectors: [
|
||||
// Assign it to `foo` tags.
|
||||
{
|
||||
selector: 'foo',
|
||||
format: 'fooBlockFormatter',
|
||||
options: { leadingLineBreaks: 1, trailingLineBreaks: 1 }
|
||||
}
|
||||
]
|
||||
});
|
||||
console.log(text); // Hello World!
|
||||
```
|
||||
|
||||
New in version 9: metadata object can be provided as the last optional argument of the `convert` function (or the function returned by `compile` function). It can be accessed by formatters as `builder.metadata`.
|
||||
|
||||
Refer to [generic formatters](https://github.com/html-to-text/node-html-to-text/blob/master/packages/base/src/generic-formatters.js) of the base package and [text formatters](https://github.com/html-to-text/node-html-to-text/blob/master/packages/html-to-text/src/text-formatters.js) of this package for more examples. The easiest way to write your own is to pick an existing one and customize.
|
||||
|
||||
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.
|
||||
|
||||
#### Custom metadata
|
||||
|
||||
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.
|
||||
|
||||
It is supplied as an extra argument to the convert function:
|
||||
|
||||
```javascript
|
||||
import { compile, convert } from 'html-to-text';
|
||||
|
||||
// for batch use:
|
||||
const compiledConvert = compile(options);
|
||||
let text = compiledConvert(html, metadata);
|
||||
|
||||
// for single use:
|
||||
let text = convert(html, options, metadata);
|
||||
```
|
||||
|
||||
And it can be accessed within formatter functions as `builder.metadata`.
|
||||
|
||||
#### Call other formatters from a custom formatter
|
||||
|
||||
Most of the times this is *not* what you actually need. Most practical problems can be solved with [selectors](#selectors).
|
||||
|
||||
If you really need to inspect the node internals, not just attributes, then you can do it like this:
|
||||
|
||||
```javascript
|
||||
const options = {
|
||||
// ...
|
||||
formatters: {
|
||||
filterBlockFormatter: function (elem, walk, builder, formatOptions) {
|
||||
// all built-in and custom formatters available by name
|
||||
const blockFormatter = builder.options.formatters['block'];
|
||||
if (blockFormatter && elem.children.some(/* predicate */)) {
|
||||
blockFormatter(elem, walk, builder, formatOptions);
|
||||
}
|
||||
}
|
||||
},
|
||||
selectors: [
|
||||
{
|
||||
selector: 'div.questionable',
|
||||
format: 'filterBlockFormatter',
|
||||
options: { leadingLineBreaks: 1, trailingLineBreaks: 1 }
|
||||
}
|
||||
],
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
* Input text: [test.html](https://github.com/html-to-text/node-html-to-text/blob/master/packages/html-to-text/test/test.html)
|
||||
* Output text: [test.txt](https://github.com/html-to-text/node-html-to-text/blob/master/packages/html-to-text/test/test.txt)
|
||||
|
||||
## Contributors
|
||||
|
||||
* [@mlegenhausen](https://github.com/mlegenhausen) - creator;
|
||||
* [@KillyMXI](https://github.com/KillyMXI) - maintainer since 2020;
|
||||
* Everyone else who [added something](https://github.com/html-to-text/node-html-to-text/graphs/contributors) to the tool or helped us shaping it via [issues](https://github.com/html-to-text/node-html-to-text/issues) and [PRs](https://github.com/html-to-text/node-html-to-text/pulls).
|
||||
|
||||
## License
|
||||
|
||||
[MIT License](https://github.com/html-to-text/node-html-to-text/blob/master/LICENSE)
|
2157
node_modules/html-to-text/lib/html-to-text.cjs
generated
vendored
Normal file
2157
node_modules/html-to-text/lib/html-to-text.cjs
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2147
node_modules/html-to-text/lib/html-to-text.mjs
generated
vendored
Normal file
2147
node_modules/html-to-text/lib/html-to-text.mjs
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
62
node_modules/html-to-text/package.json
generated
vendored
Normal file
62
node_modules/html-to-text/package.json
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
{
|
||||
"name": "html-to-text",
|
||||
"version": "9.0.5",
|
||||
"description": "Advanced html to plain text converter",
|
||||
"keywords": [
|
||||
"html",
|
||||
"node",
|
||||
"text",
|
||||
"mail",
|
||||
"plain",
|
||||
"converter"
|
||||
],
|
||||
"license": "MIT",
|
||||
"author": "Malte Legenhausen <legenhausen@werk85.de>",
|
||||
"contributors": [
|
||||
"KillyMXI <killy@mxii.eu.org>"
|
||||
],
|
||||
"homepage": "https://github.com/html-to-text/node-html-to-text",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/html-to-text/node-html-to-text.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/html-to-text/node-html-to-text/issues"
|
||||
},
|
||||
"type": "module",
|
||||
"main": "./lib/html-to-text.cjs",
|
||||
"module": "./lib/html-to-text.mjs",
|
||||
"exports": {
|
||||
"import": "./lib/html-to-text.mjs",
|
||||
"require": "./lib/html-to-text.cjs"
|
||||
},
|
||||
"files": [
|
||||
"lib",
|
||||
"README.md",
|
||||
"CHANGELOG.md",
|
||||
"LICENSE"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"scripts": {
|
||||
"build:rollup": "rollup -c",
|
||||
"build": "npm run clean && npm run build:rollup && npm run copy:license",
|
||||
"clean": "rimraf lib",
|
||||
"copy:license": "copyfiles -f ../../LICENSE .",
|
||||
"cover": "c8 --reporter=lcov --reporter=text-summary mocha -t 20000",
|
||||
"test": "mocha"
|
||||
},
|
||||
"dependencies": {
|
||||
"@selderee/plugin-htmlparser2": "^0.11.0",
|
||||
"deepmerge": "^4.3.1",
|
||||
"dom-serializer": "^2.0.0",
|
||||
"htmlparser2": "^8.0.2",
|
||||
"selderee": "^0.11.0"
|
||||
},
|
||||
"mocha": {
|
||||
"node-option": [
|
||||
"experimental-specifier-resolution=node"
|
||||
]
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user