MCPcopy Index your code
hub / github.com/tinymce/tinymce / HtmlSerializer

Function HtmlSerializer

modules/tinymce/src/core/main/ts/api/html/Serializer.ts:27–169  ·  view source on GitHub ↗
(settings: HtmlSerializerSettings = {}, schema: Schema = Schema())

Source from the content-addressed store, hash-verified

25 */
26
27const HtmlSerializer = (settings: HtmlSerializerSettings = {}, schema: Schema = Schema()): HtmlSerializer => {
28 const writer = Writer(settings);
29
30 settings.validate = 'validate' in settings ? settings.validate : true;
31
32 /**
33 * Serializes the specified node into a string.
34 *
35 * @method serialize
36 * @param {tinymce.html.Node} node Node instance to serialize.
37 * @return {String} String with HTML based on the DOM tree.
38 * @example
39 * tinymce.html.Serializer().serialize(tinymce.html.DomParser().parse('<p>text</p>'));
40 */
41 const serialize = (node: AstNode): string => {
42 const validate = settings.validate;
43
44 const handlers: Record<number, (node: AstNode) => void> = {
45 // #text
46 3: (node) => {
47 writer.text(node.value ?? '', node.raw);
48 },
49
50 // #comment
51 8: (node) => {
52 writer.comment(node.value ?? '');
53 },
54
55 // Processing instruction
56 7: (node) => {
57 writer.pi(node.name, node.value);
58 },
59
60 // Doctype
61 10: (node) => {
62 writer.doctype(node.value ?? '');
63 },
64
65 // CDATA
66 4: (node) => {
67 writer.cdata(node.value ?? '');
68 },
69
70 // Document fragment
71 11: (node) => {
72 let tempNode: AstNode | null | undefined = node;
73 if ((tempNode = tempNode.firstChild)) {
74 do {
75 walk(tempNode);
76 } while ((tempNode = tempNode.next));
77 }
78 }
79 };
80
81 writer.reset();
82
83 const walk = (node: AstNode) => {
84 const handler = handlers[node.type];

Callers 15

DomParserTest.tsFile · 0.50
testSpecialElementFunction · 0.50
SerializerTest.tsFile · 0.50
SchemaTest.tsFile · 0.50
toHtmlFunction · 0.50
toHtmlFunction · 0.50
serializeNodeFunction · 0.50
cleanContentFunction · 0.50
serializeContentFunction · 0.50
setContentStringFunction · 0.50
setContentTreeFunction · 0.50

Calls 2

SchemaFunction · 0.70
WriterFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…