Skip to content

Commit fd84695

Browse files
authored
DOC-2326: Improve custom_elements documentation (#4010)
- Document String and Object type formats with clear sections - Add structured record format with extends, attributes, children, padEmpty, and componentUrl properties - Add @global attribute preset section and tables for html4/html5 schemas - Fix componentsUrl to componentUrl (correct API name) - Update example with padEmpty and componentUrl usage
1 parent 179f9c8 commit fd84695

1 file changed

Lines changed: 41 additions & 13 deletions

File tree

modules/ROOT/partials/configuration/custom_elements.adoc

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ This option enables you to specify non-HTML elements for the editor.
55

66
This way you can handle non-HTML elements inside an HTML editor. You can prefix the element names with a `+~+` if you want the element to behave as a `+span+` element and not a `+div+` element.
77

8-
*Type:* `+String+`
8+
*Type:* `+String+` or `+Object+`
9+
10+
=== Simple string format
911

1012
[source,js]
1113
----
@@ -16,12 +18,29 @@ tinymce.init({
1618
});
1719
----
1820

19-
* **Custom Element Structure:** The custom_elements option and the `addCustomElements` API supports more complex structures. This structure is defined by a record where the key represents the name of the element, and the value corresponds to a detailed specification.
20-
* **Attributes and Inheritance:** Elements inherit attributes and children from other specified elements using the `+extends: "div"+` property in the `custom_elements` spec.
21-
* **Attribute and Children Specifications:** The `custom_elements` spec includes properties such as `attributes` which lists attribute names, or `children` which lists valid child element names. The `children` property includes presets like `@global`, `@blocks`, `@phrasing`, and `@flow`.
22-
* **Web Components Support:** Custom elements can specify a `+componentsUrl+` property to load web component scripts into the editor.
21+
=== Record format
22+
23+
The `custom_elements` option and the `addCustomElements` API support a record structure. The key is the element name, and the value is a specification object with the following properties:
24+
25+
`+extends+` (string)::
26+
The element name from which the new element inherits its default properties. Using `extends` also adds the new element as a valid child wherever the extended element is valid. For example, `extends: "div"` makes the custom element block-level and allows it wherever `div` is allowed.
27+
28+
`+attributes+` (array of strings)::
29+
List of attribute names or the preset `@global`. Each string is either an attribute name or the preset `@global`, which expands to the schema's global attributes (see <<attribute-preset-global>>). For example: `["@global", "data-type", "data-id"]`.
30+
31+
`+children+` (array of strings)::
32+
List of valid child element names or presets. Each string is either an element name or one of the presets `@blocks`, `@phrasing`, or `@flow`. See <<html4>>, <<html5>>, and <<html5-strict>> for the exact element sets per schema.
33+
34+
`+padEmpty+` (boolean)::
35+
Defaults to `false`. When `true`, the element is padded with content (for example, a non-breaking space) when saved so that it always has some content. Use for elements that must not be empty.
2336

24-
HTML Element Sets: The exact element sets for each preset, depending on the schema set (html4, html5, or html5-strict), can be found in the below tables.
37+
`+componentUrl+` (string)::
38+
URL of the web component script to load into the editor. Use when the custom element is a web component that requires its script to render.
39+
40+
[[attribute-preset-global]]
41+
=== Attribute preset: `@global`
42+
43+
The `@global` preset in the `attributes` array expands to the schema's global attributes. The exact set depends on the schema type:
2544

2645
[[html4]]
2746
=== HTML Element Sets: `html4`
@@ -32,6 +51,7 @@ HTML Element Sets: The exact element sets for each preset, depending on the sche
3251
| @blocks | address, blockquote, div, dl, fieldset, form, h1, h2, h3, h4, h5, h6, hr, menu, ol, p, pre, table, ul, center, dir, isindex, noframes
3352
| @phrasing | a, abbr, b, bdo, br, button, cite, code, del, dfn, em, embed, i, iframe, img, input, ins, kbd, label, map, noscript, object, q, s, samp, script, select, small, span, strong, sub, sup, textarea, u, var, #text, #comment, acronym, applet, basefont, big, font, strike, tt
3453
| @flow | Same as @blocks + @phrasing
54+
| @global (attributes) | id, accesskey, class, dir, lang, style, tabindex, title, role, xml:lang
3555
|===
3656

3757
[[html5]]
@@ -43,6 +63,7 @@ HTML Element Sets: The exact element sets for each preset, depending on the sche
4363
| @blocks | address, blockquote, div, dl, fieldset, form, h1, h2, h3, h4, h5, h6, hr, menu, ol, p, pre, table, ul, article, aside, details, dialog, figure, main, header, footer, hgroup, section, nav, a, ins, del, canvas, map, center, dir, isindex, noframes
4464
| @phrasing | a, abbr, b, bdo, br, button, cite, code, del, dfn, em, embed, i, iframe, img, input, ins, kbd, label, map, noscript, object, q, s, samp, script, select, small, span, strong, sub, sup, textarea, u, var, #text, #comment, audio, canvas, command, data, datalist, mark, meter, output, picture, progress, time, wbr, video, ruby, bdi, keygen, svg, acronym, applet, basefont, big, font, strike, tt
4565
| @flow | Same as @blocks + @phrasing
66+
| @global (attributes) | id, accesskey, class, dir, lang, style, tabindex, title, role, contenteditable, contextmenu, draggable, dropzone, hidden, spellcheck, translate, itemprop, itemscope, itemtype, xml:lang
4667
|===
4768

4869
[[html5-strict]]
@@ -54,9 +75,10 @@ HTML Element Sets: The exact element sets for each preset, depending on the sche
5475
| @blocks | address, blockquote, div, dl, fieldset, form, h1, h2, h3, h4, h5, h6, hr, menu, ol, p, pre, table, ul, article, aside, details, dialog, figure, main, header, footer, hgroup, section, nav, a, ins, del, canvas, map
5576
| @phrasing | a, abbr, b, bdo, br, button, cite, code, del, dfn, em, embed, i, iframe, img, input, ins, kbd, label, map, noscript, object, q, s, samp, script, select, small, span, strong, sub, sup, textarea, u, var, #text, #comment, audio, canvas, command, data, datalist, mark, meter, output, picture, progress, time, wbr, video, ruby, bdi, keygen, svg
5677
| @flow | Same as @blocks + @phrasing
78+
| @global (attributes) | id, accesskey, class, dir, lang, style, tabindex, title, role, contenteditable, contextmenu, draggable, dropzone, hidden, spellcheck, translate, itemprop, itemscope, itemtype
5779
|===
5880

59-
=== Example using `+custom_elements+` with presets such as `@blocks`, `@phrasing`, and `@flow`.
81+
=== Example using `+custom_elements+` with presets such as `@blocks`, `@phrasing`, and `@flow`
6082

6183
[source, js]
6284
----
@@ -99,27 +121,33 @@ tinymce.init({
99121
});
100122
----
101123

102-
=== Example using `+custom_elements+` with block-level and inline-level components.
124+
[[example-using-custom_elements-with-block-level-and-inline-level-components]]
125+
=== Example using `+custom_elements+` with `padEmpty` and `componentUrl`
103126

104127
[source, js]
105128
----
106129
tinymce.init({
107130
selector: "textarea",
108131
custom_elements: {
109-
// Block-level custom element (behaves like a div)
132+
// Custom element that is padded when empty
133+
"my-empty-padded": {
134+
extends: "div",
135+
padEmpty: true,
136+
},
137+
// Block-level custom element (behaves like a div) with web component
110138
"my-custom-block": {
111139
extends: "div",
112140
attributes: ["@global", "data-type", "data-id"],
113141
children: ["@flow"],
114-
componentsUrl: "/path/to/block-component.js"
142+
componentUrl: "/path/to/block-component.js"
115143
},
116-
// Inline-level custom element (behaves like a span)
144+
// Inline-level custom element (behaves like a span) with web component
117145
"my-custom-inline": {
118146
extends: "span",
119147
attributes: ["@global", "data-value"],
120148
children: ["@phrasing"],
121-
componentsUrl: "/path/to/inline-component.js"
149+
componentUrl: "/path/to/inline-component.js"
122150
}
123151
}
124152
});
125-
----
153+
----

0 commit comments

Comments
 (0)