diff --git a/readme.md b/readme.md index 781eb380..82f64960 100644 --- a/readme.md +++ b/readme.md @@ -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 -
this is the text
-``` - -### 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 diff --git a/src/__fixtures__/16-normalize_whitespace.json b/src/__fixtures__/16-normalize_whitespace.json deleted file mode 100644 index a9d79b70..00000000 --- a/src/__fixtures__/16-normalize_whitespace.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "name": "Normalize whitespace", - "options": { - "normalizeWhitespace": true - }, - "html": "Line one\n
\t \r\n\f
\nline two
x
", - "expected": [ - { - "data": "Line one ", - "type": "text" - }, - { - "type": "tag", - "name": "br", - "attribs": {} - }, - { - "data": " ", - "type": "text" - }, - { - "type": "tag", - "name": "br", - "attribs": {} - }, - { - "data": " line two", - "type": "text" - }, - { - "type": "tag", - "name": "font", - "attribs": {}, - "children": [ - { - "type": "tag", - "name": "br", - "attribs": {} - }, - { - "data": " x ", - "type": "text" - } - ] - } - ] -} diff --git a/src/index.ts b/src/index.ts index ec86896d..3dd38bda 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,8 +12,6 @@ import { export * from "./node"; -const reWhitespace = /\s+/g; - export interface DomHandlerOptions { /** * Add a `startIndex` property to nodes. @@ -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. * @@ -53,7 +41,6 @@ export interface DomHandlerOptions { // Default options const defaultOpts: DomHandlerOptions = { - normalizeWhitespace: false, withStartIndices: false, withEndIndices: false, xmlMode: false, @@ -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;