Skip to content

Commit

Permalink
refactor: Remove deprecated normalizeWhitespace option (#614)
Browse files Browse the repository at this point in the history
  • Loading branch information
fb55 committed Aug 24, 2021
1 parent 3b01ac7 commit 018ddf9
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 144 deletions.
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

0 comments on commit 018ddf9

Please sign in to comment.