-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increase the probability that removeUnnecessarySpan and mergeNode wil…
…l be triggered.
- Loading branch information
Showing
2 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
20 changes: 17 additions & 3 deletions
20
packages/roosterjs-content-model-dom/lib/modelToDom/optimizers/optimize.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,36 @@ | ||
import { enumerateComputedStyle, removeUnnecessaryAttribute, removeUnnecessarySpan, removeUnnecessaryStyle } from './removeUnnecessarySpan'; | ||
import { isEntityElement } from '../../domUtils/entityUtils'; | ||
import { mergeNode } from './mergeNode'; | ||
import { removeUnnecessarySpan } from './removeUnnecessarySpan'; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export function optimize(root: Node) { | ||
export function optimize(root: Node, isRecursive = false) { | ||
/** | ||
* Do no do any optimization to entity | ||
*/ | ||
if (isEntityElement(root)) { | ||
return; | ||
} | ||
if (!isRecursive && root.parentElement != null) { | ||
let computedAttributes = {} as Record<string, Attr>; | ||
// html doesn't provide computed attributes, use parent's attributes directly | ||
Array.from(root.parentElement.attributes).forEach((attr) => { | ||
computedAttributes[attr.name] = attr; | ||
}); | ||
removeUnnecessaryAttribute(root, computedAttributes); | ||
|
||
let computedStyle = {} as Record<string, Set<string>>; | ||
enumerateComputedStyle(root.parentElement, (key, values) => { | ||
computedStyle[key] = values; | ||
}); | ||
removeUnnecessaryStyle(root, computedStyle); | ||
} | ||
|
||
removeUnnecessarySpan(root); | ||
mergeNode(root); | ||
|
||
for (let child = root.firstChild; child; child = child.nextSibling) { | ||
optimize(child); | ||
optimize(child, true); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
packages/roosterjs-content-model-dom/lib/modelToDom/optimizers/removeUnnecessarySpan.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters