import { context, describe, it } from '@ephox/bedrock-client'; import { Arr, Fun, Obj } from '@ephox/katamari'; import { PlatformDetection } from '@ephox/sand'; import { assert } from 'chai'; import Env from 'tinymce/core/api/Env'; import { BlobCache, BlobInfo } from 'tinymce/core/api/file/BlobCache'; import DomParser, { ParserArgs, ParserFilterCallback } from 'tinymce/core/api/html/DomParser'; import AstNode, { Attributes } from 'tinymce/core/api/html/Node'; import Schema, { SchemaElement } from 'tinymce/core/api/html/Schema'; import HtmlSerializer from 'tinymce/core/api/html/Serializer'; interface ParseTestResult { readonly nodes: AstNode[]; readonly name: string; readonly args: ParserArgs; } describe('browser.tinymce.core.html.DomParserTest', () => { const browser = PlatformDetection.detect().browser; const schema = Schema({ valid_elements: '*[class|title]' }); const serializer = HtmlSerializer({}, schema); const countNodes = (node: AstNode, counter: Record = {}) => { if (node.name in counter) { counter[node.name]++; } else { counter[node.name] = 1; } for (let sibling = node.firstChild; sibling; sibling = sibling.next) { countNodes(sibling, counter); } return counter; }; schema.addValidChildren('+body[style]'); it('Parse element', () => { const parser = DomParser({}, schema); const root = parser.parse('test'); assert.equal(serializer.serialize(root), 'test', 'Inline element'); assert.equal(root.firstChild?.type, 1, 'Element type'); assert.equal(root.firstChild?.name, 'b', 'Element name'); assert.deepEqual( root.firstChild?.attributes, [ { name: 'title', value: 'title' }, { name: 'class', value: 'class' }, ] as unknown as Attributes, 'Element attributes' ); assert.deepEqual(countNodes(root), { 'body': 1, 'b': 1, '#text': 1 }, 'Element attributes (count)'); }); it('Retains code inside a script', () => { const parser = DomParser({}, schema); const root = parser.parse(' \t\r\n