Skip to content

Commit

Permalink
Version 8.2.0, fix selectors processing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
KillyMXI committed Apr 7, 2022
1 parent 74b414c commit c5b768e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 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`.
Expand Down
6 changes: 3 additions & 3 deletions lib/html-to-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,19 @@ function compile (options = {}) {
}
);
options.formatters = Object.assign({}, defaultFormatters, options.formatters);
options.selectors = mergeDuplicatesPreferLast(options.selectors, (s => s.selector));

handleDeprecatedOptions(options);

const uniqueSelectors = mergeDuplicatesPreferLast(options.selectors, (s => s.selector));
const selectorsWithoutFormat = uniqueSelectors.filter(s => !s.format);
const selectorsWithoutFormat = options.selectors.filter(s => !s.format);
if (selectorsWithoutFormat.length) {
throw new Error(
'Following selectors have no specified format: ' +
selectorsWithoutFormat.map(s => `\`${s.selector}\``).join(', ')
);
}
const picker = new selderee.DecisionTree(
uniqueSelectors.map(s => [s.selector, s])
options.selectors.map(s => [s.selector, s])
).build(hp2Builder);

const baseSelectorsPicker = new selderee.DecisionTree(
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "html-to-text",
"version": "8.1.1",
"version": "8.2.0",
"description": "Advanced html to plain text converter",
"license": "MIT",
"author": {
Expand Down
11 changes: 11 additions & 0 deletions test/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,17 @@ describe('tags', function () {
expect(htmlToText(html)).to.equal(expected);
});

it('should return link without brackets if noLinkBrackets is set to true (deprecated option)', function () {
const html = '<a href="http://my.link">test</a>';
const expected = 'test http://my.link';
const options = {
selectors: [
{ selector: 'a', options: { noLinkBrackets: true } }
]
};
expect(htmlToText(html, options)).to.equal(expected);
});

it('should return link without brackets if linkBrackets is set to false', function () {
const html = '<a href="http://my.link">test</a>';
const expected = 'test http://my.link';
Expand Down

0 comments on commit c5b768e

Please sign in to comment.