OXIESEC PANEL
- Current Dir:
/
/
var
/
www
/
reader
/
_backup
/
tinymce
/
tinymce
/
src
/
core
/
main
/
ts
/
content
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
02/20/2020 05:44:43 AM
rwxr-xr-x
📄
EditorContent.ts
524 bytes
02/20/2020 05:42:39 AM
rw-r--r--
📄
GetContent.ts
2.37 KB
02/20/2020 05:42:39 AM
rw-r--r--
📄
InsertContent.ts
11.61 KB
02/20/2020 05:42:41 AM
rw-r--r--
📄
InsertList.ts
5.85 KB
02/20/2020 05:42:41 AM
rw-r--r--
📄
NbspTrim.ts
1.88 KB
02/20/2020 05:42:42 AM
rw-r--r--
📄
SetContent.ts
4.45 KB
02/20/2020 05:42:42 AM
rw-r--r--
Editing: GetContent.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 { HTMLElement } from '@ephox/dom-globals'; import { Option, Fun } from '@ephox/katamari'; import { Element } from '@ephox/sugar'; import Editor from '../api/Editor'; import Node from '../api/html/Node'; import Tools from '../api/util/Tools'; import TrimHtml from '../dom/TrimHtml'; import Zwsp from '../text/Zwsp'; import Settings from '../api/Settings'; import { isWsPreserveElement } from '../dom/ElementType'; const defaultFormat = 'html'; type Content = string | Node; export interface GetContentArgs { format?: 'raw' | 'text' | 'html' | 'tree'; get?: boolean; content?: string; getInner?: boolean; no_events?: boolean; } const trimEmptyContents = (editor: Editor, html: string): string => { const blockName = Settings.getForcedRootBlock(editor); const emptyRegExp = new RegExp(`^(<${blockName}[^>]*>( | |\\s|\u00a0|<br \\/>|)<\\/${blockName}>[\r\n]*|<br \\/>[\r\n]*)$`); return html.replace(emptyRegExp, ''); }; const getContentFromBody = (editor: Editor, args: GetContentArgs, body: HTMLElement): Content => { let content; args.format = args.format ? args.format : defaultFormat; args.get = true; args.getInner = true; if (!args.no_events) { editor.fire('BeforeGetContent', args); } if (args.format === 'raw') { content = Tools.trim(TrimHtml.trimExternal(editor.serializer, body.innerHTML)); } else if (args.format === 'text') { content = Zwsp.trim(body.innerText || body.textContent); } else if (args.format === 'tree') { return editor.serializer.serialize(body, args); } else { content = trimEmptyContents(editor, editor.serializer.serialize(body, args)); } if (args.format !== 'text' && !isWsPreserveElement(Element.fromDom(body))) { args.content = Tools.trim(content); } else { args.content = content; } if (!args.no_events) { editor.fire('GetContent', args); } return args.content; }; export const getContent = (editor: Editor, args: GetContentArgs = {}): Content => { return Option.from(editor.getBody()) .fold( Fun.constant(args.format === 'tree' ? new Node('body', 11) : ''), (body) => getContentFromBody(editor, args, body) ); };