OXIESEC PANEL
- Current Dir:
/
/
var
/
www
/
reader
/
_backup
/
tinymce
/
tinymce
/
src
/
core
/
main
/
ts
/
dom
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
02/20/2020 05:44:43 AM
rwxr-xr-x
📄
Dimensions.ts
1.28 KB
02/20/2020 05:42:59 AM
rw-r--r--
📄
DomSerializer.ts
4.65 KB
02/20/2020 05:42:59 AM
rw-r--r--
📄
DomSerializerFilters.ts
6.91 KB
02/20/2020 05:43:00 AM
rw-r--r--
📄
DomSerializerPreProcess.ts
1.81 KB
02/20/2020 05:43:00 AM
rw-r--r--
📄
ElementType.ts
2.39 KB
02/20/2020 05:43:01 AM
rw-r--r--
📄
Empty.ts
2.18 KB
02/20/2020 05:43:02 AM
rw-r--r--
📄
MousePosition.ts
2.37 KB
02/20/2020 05:43:03 AM
rw-r--r--
📄
NodePath.ts
970 bytes
02/20/2020 05:43:03 AM
rw-r--r--
📄
NodeType.ts
3.37 KB
02/20/2020 05:43:04 AM
rw-r--r--
📄
PaddingBr.ts
1.7 KB
02/20/2020 05:43:04 AM
rw-r--r--
📄
Parents.ts
1020 bytes
02/20/2020 05:43:05 AM
rw-r--r--
📄
Position.ts
2.9 KB
02/20/2020 05:43:05 AM
rw-r--r--
📄
RangePoint.ts
639 bytes
02/20/2020 05:43:06 AM
rw-r--r--
📄
ScrollIntoView.ts
3.27 KB
02/20/2020 05:43:07 AM
rw-r--r--
📄
StyleSheetLoader.ts
6.49 KB
02/20/2020 05:43:08 AM
rw-r--r--
📄
TrimHtml.ts
1.62 KB
02/20/2020 05:43:08 AM
rw-r--r--
📄
TrimNode.ts
2.58 KB
02/20/2020 05:43:09 AM
rw-r--r--
Editing: TrimNode.ts
Close
/** * Copyright (c) Tiny Technologies, Inc. All rights reserved. * Licensed under the LGPL or a commercial license. * For LGPL see License.txt in the project root for license information. * For commercial licenses see https://www.tiny.cloud/ */ import { Element } from '@ephox/sugar'; import * as ElementType from './ElementType'; import NodeType from './NodeType'; import Tools from '../api/util/Tools'; const surroundedBySpans = function (node) { const previousIsSpan = node.previousSibling && node.previousSibling.nodeName === 'SPAN'; const nextIsSpan = node.nextSibling && node.nextSibling.nodeName === 'SPAN'; return previousIsSpan && nextIsSpan; }; const isBookmarkNode = function (node) { return node && node.tagName === 'SPAN' && node.getAttribute('data-mce-type') === 'bookmark'; }; // W3C valid browsers tend to leave empty nodes to the left/right side of the contents - this makes sense // but we don't want that in our code since it serves no purpose for the end user // For example splitting this html at the bold element: // <p>text 1<span><b>CHOP</b></span>text 2</p> // would produce: // <p>text 1<span></span></p><b>CHOP</b><p><span></span>text 2</p> // this function will then trim off empty edges and produce: // <p>text 1</p><b>CHOP</b><p>text 2</p> const trimNode = function (dom, node) { let i, children = node.childNodes; if (NodeType.isElement(node) && isBookmarkNode(node)) { return; } for (i = children.length - 1; i >= 0; i--) { trimNode(dom, children[i]); } if (NodeType.isDocument(node) === false) { // Keep non whitespace text nodes if (NodeType.isText(node) && node.nodeValue.length > 0) { // Keep if parent element is a block or if there is some useful content const trimmedLength = Tools.trim(node.nodeValue).length; if (dom.isBlock(node.parentNode) || trimmedLength > 0) { return; } // Also keep text nodes with only spaces if surrounded by spans. // eg. "<p><span>a</span> <span>b</span></p>" should keep space between a and b if (trimmedLength === 0 && surroundedBySpans(node)) { return; } } else if (NodeType.isElement(node)) { // If the only child is a bookmark then move it up children = node.childNodes; if (children.length === 1 && isBookmarkNode(children[0])) { node.parentNode.insertBefore(children[0], node); } // Keep non empty elements and void elements if (children.length || ElementType.isVoid(Element.fromDom(node))) { return; } } dom.remove(node); } return node; }; export default { trimNode };