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

Function Writer

modules/tinymce/src/core/main/ts/api/html/Writer.ts:43–203  ·  view source on GitHub ↗
(settings?: WriterSettings)

Source from the content-addressed store, hash-verified

41}
42
43const Writer = (settings?: WriterSettings): Writer => {
44 const html: string[] = [];
45
46 settings = settings || {};
47 const indent = settings.indent;
48 const indentBefore = makeMap(settings.indent_before || '');
49 const indentAfter = makeMap(settings.indent_after || '');
50 const encode = Entities.getEncodeFunc(settings.entity_encoding || 'raw', settings.entities);
51 const htmlOutput = settings.element_format !== 'xhtml';
52
53 return {
54 /**
55 * Writes a start element, such as `<p id="a">`.
56 *
57 * @method start
58 * @param {String} name Name of the element.
59 * @param {Array} attrs Optional array of objects containing an attribute name and value, or undefined if the element has no attributes.
60 * @param {Boolean} empty Optional empty state if the tag should serialize as a void element. For example: `<img />`
61 */
62 start: (name: string, attrs?: Attributes | null, empty?: boolean) => {
63 if (indent && indentBefore[name] && html.length > 0) {
64 const value = html[html.length - 1];
65
66 if (value.length > 0 && value !== '\n') {
67 html.push('\n');
68 }
69 }
70
71 html.push('<', name);
72
73 if (attrs) {
74 for (let i = 0, l = attrs.length; i < l; i++) {
75 const attr = attrs[i];
76 html.push(' ', attr.name, '="', encode(attr.value, true), '"');
77 }
78 }
79
80 if (!empty || htmlOutput) {
81 html[html.length] = '>';
82 } else {
83 html[html.length] = ' />';
84 }
85
86 if (empty && indent && indentAfter[name] && html.length > 0) {
87 const value = html[html.length - 1];
88
89 if (value.length > 0 && value !== '\n') {
90 html.push('\n');
91 }
92 }
93 },
94
95 /**
96 * Writes an end element, such as `</p>`.
97 *
98 * @method end
99 * @param {String} name Name of the element.
100 */

Callers 2

HtmlSerializerFunction · 0.70
WriterTest.tsFile · 0.50

Calls 3

encodeFunction · 0.85
replaceMethod · 0.80
makeMapFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…