Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Remove deprecated normalizeWhitespace option #614

Merged
merged 2 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 0 additions & 71 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,77 +76,6 @@ When the parser is used in a non-streaming fashion, `endIndex` is an integer
indicating the position of the end of the node in the document.
The default value is `false`.

## Option: `normalizeWhitespace` _(deprecated)_

Replace all whitespace with single spaces.
The default value is `false`.

**Note:** Enabling this might break your markup.

For the following examples, this HTML will be used:

```html
<font> <br />this is the text <font></font></font>
```

### Example: `normalizeWhitespace: true`

```javascript
[
{
type: "tag",
name: "font",
children: [
{
data: " ",
type: "text",
},
{
type: "tag",
name: "br",
},
{
data: "this is the text ",
type: "text",
},
{
type: "tag",
name: "font",
},
],
},
];
```

### Example: `normalizeWhitespace: false`

```javascript
[
{
type: "tag",
name: "font",
children: [
{
data: "\n\t",
type: "text",
},
{
type: "tag",
name: "br",
},
{
data: "this is the text\n",
type: "text",
},
{
type: "tag",
name: "font",
},
],
},
];
```

---

License: BSD-2-Clause
Expand Down
47 changes: 0 additions & 47 deletions src/__fixtures__/16-normalize_whitespace.json

This file was deleted.

27 changes: 1 addition & 26 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import {

export * from "./node";

const reWhitespace = /\s+/g;

export interface DomHandlerOptions {
/**
* Add a `startIndex` property to nodes.
Expand All @@ -33,16 +31,6 @@ export interface DomHandlerOptions {
*/
withEndIndices?: boolean;

/**
* Replace all whitespace with single spaces.
*
* **Note:** Enabling this might break your markup.
*
* @default false
* @deprecated
*/
normalizeWhitespace?: boolean;

/**
* Treat the markup as XML.
*
Expand All @@ -53,7 +41,6 @@ export interface DomHandlerOptions {

// Default options
const defaultOpts: DomHandlerOptions = {
normalizeWhitespace: false,
withStartIndices: false,
withEndIndices: false,
};
Expand Down Expand Up @@ -165,23 +152,11 @@ export class DomHandler {
}

public ontext(data: string): void {
const { normalizeWhitespace } = this.options;
const { lastNode } = this;

if (lastNode && lastNode.type === ElementType.Text) {
if (normalizeWhitespace) {
lastNode.data = (lastNode.data + data).replace(
reWhitespace,
" "
);
} else {
lastNode.data += data;
}
lastNode.data += data;
} else {
if (normalizeWhitespace) {
data = data.replace(reWhitespace, " ");
}

const node = new Text(data);
this.addNode(node);
this.lastNode = node;
Expand Down