From 17a0afa032b5cc08e65e017197eeadaa8b16069e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20B=C3=B6hm?= <188768+fb55@users.noreply.github.com> Date: Tue, 24 Aug 2021 13:38:01 +0100 Subject: [PATCH 1/2] refactor: Remove deprecated `normalizeWhitespace` option __BREAKING__ This option was never useful, as it could just break someone's markup. Instead, use a tool that specialises in minifying HTML such as `html-minifier-terser`. --- src/index.ts | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/src/index.ts b/src/index.ts index df6b4fad..8e9c0c5e 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, }; @@ -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; From 581dfec48e6cd7a20cc600b52876905a4707997c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20B=C3=B6hm?= <188768+fb55@users.noreply.github.com> Date: Tue, 24 Aug 2021 13:46:05 +0100 Subject: [PATCH 2/2] rm other references --- readme.md | 71 ------------------- src/__fixtures__/16-normalize_whitespace.json | 47 ------------ 2 files changed, 118 deletions(-) delete mode 100644 src/__fixtures__/16-normalize_whitespace.json 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" - } - ] - } - ] -}