Skip to content

Commit

Permalink
Revert "Revert "Revert "Revert "refactor: Remove deprecated `normaliz…
Browse files Browse the repository at this point in the history
…eWhitespace` option (#614)""""

This reverts commit 636a25b.
  • Loading branch information
fb55 committed Nov 30, 2021
1 parent d28917e commit e15248b
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,
xmlMode: false,
Expand Down Expand Up @@ -166,26 +153,14 @@ 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;
if (this.options.withEndIndices) {
lastNode.endIndex = this.parser!.endIndex;
}
} else {
if (normalizeWhitespace) {
data = data.replace(reWhitespace, " ");
}

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

0 comments on commit e15248b

Please sign in to comment.