Skip to content

Commit

Permalink
refactor: Remove deprecated normalizeWhitespace option
Browse files Browse the repository at this point in the history
__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`.
  • Loading branch information
fb55 committed Aug 24, 2021
1 parent 3b01ac7 commit 17a0afa
Showing 1 changed file with 1 addition and 26 deletions.
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 17a0afa

Please sign in to comment.