From 71599e72675b105580eb4a9b1efca904d59d5ee5 Mon Sep 17 00:00:00 2001 From: Zihua Li Date: Mon, 12 Feb 2024 10:53:32 +0800 Subject: [PATCH] Remove unnecessary lodash usages --- CHANGELOG.md | 2 ++ .../normalizeExternalHTML/normalizers/msWord.ts | 15 ++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bdb5459c4..7bdc68f2ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # [Unreleased] +- Remove unnecessary lodash usages. + # 2.0.0-rc.0 - **Clipboard** Convert newlines between inline elements to a space. diff --git a/packages/quill/src/modules/normalizeExternalHTML/normalizers/msWord.ts b/packages/quill/src/modules/normalizeExternalHTML/normalizers/msWord.ts index 2495e931ff..e6f64f6a0c 100644 --- a/packages/quill/src/modules/normalizeExternalHTML/normalizers/msWord.ts +++ b/packages/quill/src/modules/normalizeExternalHTML/normalizers/msWord.ts @@ -1,5 +1,3 @@ -import _ from 'lodash'; - const ignoreRegexp = /\bmso-list:[^;]*ignore/i; const idRegexp = /\bmso-list:[^;]*\bl(\d+)/i; const indentRegexp = /\bmso-list:[^;]*\blevel(\d+)/i; @@ -30,9 +28,16 @@ const parseListItem = (element: Element, html: string) => { // 2. "1" in "level1" means the indent level, starting from 1. const normalizeListItem = (doc: Document) => { const msoList = Array.from(doc.querySelectorAll('[style*=mso-list]')); - const [ignored, others] = _.partition(msoList, (node) => - (node.getAttribute('style') || '').match(ignoreRegexp), - ); + const ignored: Element[] = []; + const others: Element[] = []; + msoList.forEach((node) => { + const shouldIgnore = (node.getAttribute('style') || '').match(ignoreRegexp); + if (shouldIgnore) { + ignored.push(node); + } else { + others.push(node); + } + }); // Each list item contains a marker wrapped with "mso-list: Ignore". ignored.forEach((node) => node.parentNode?.removeChild(node));