You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The NodeClass extension allows you to apply arbitrary CSS classes to block-level nodes (paragraphs, tables, table cells, etc.) using global attributes. This provides a clean, semantic way to style entire elements without requiring individual node type extensions.
4
+
The NodeClass extension allows you to apply arbitrary CSS classes to both block-level nodes (paragraphs, tables, table cells, etc.) and marks (bold, italic, links, etc.) using global attributes. This provides a clean, semantic way to style elements without requiring individual node or mark type extensions.
5
5
6
-
Unlike TextClass which applies to inline text using ``<span>`` tags, NodeClass works with block-level elements by adding CSS classes directly to their HTML tags (e.g., ``<p class="highlight">``, ``<table class="bordered">``).
6
+
Unlike TextClass which applies to inline text using ``<span>`` tags, NodeClass works with both block-level elements and marks by adding CSS classes directly to their HTML tags (e.g., ``<p class="highlight">``, ``<table class="bordered">``, ``<strong class="emphasis">``).
7
7
8
8
Basic Usage
9
9
-----------
10
10
11
-
To use the NodeClass extension, configure it with CSS classes organized by node type. Each class can be specified as:
11
+
To use the NodeClass extension, configure it with CSS classes organized by node or mark type. Each class can be specified as:
12
12
13
13
- A string (class name and display title will be the same)
14
14
- An object with ``className`` and ``title`` properties for custom display names
@@ -25,6 +25,7 @@ To use the NodeClass extension, configure it with CSS classes organized by node
25
25
"Table": True,
26
26
"NodeClass": {
27
27
"cssClasses": {
28
+
# Node types
28
29
"paragraph": {
29
30
"title": "Paragraph",
30
31
"cssClasses": [
@@ -56,20 +57,20 @@ To use the NodeClass extension, configure it with CSS classes organized by node
@@ -128,14 +136,20 @@ When creating custom presets, you can configure the NodeClass extension in JavaS
128
136
table: [
129
137
{ className:"bordered", title:"Bordered Table" },
130
138
{ className:"striped", title:"Striped Rows" }
139
+
],
140
+
bold: [
141
+
{ className:"emphasis", title:"Emphasis" },
142
+
{ className:"important", title:"Important" }
131
143
]
132
144
}
133
145
})
134
146
135
-
Supported Node Types
136
-
--------------------
147
+
Supported Types
148
+
---------------
149
+
150
+
The following node and mark types are supported for CSS class application:
137
151
138
-
The following node types are supported for CSS class application:
152
+
**Node Types:**
139
153
140
154
- **paragraph**: Paragraph elements (``<p>``)
141
155
- **table**: Table elements (``<table>``)
@@ -148,45 +162,58 @@ The following node types are supported for CSS class application:
148
162
- **blockquote**: Blockquote elements (``<blockquote>``)
149
163
- **codeBlock**: Code block elements (``<pre>``)
150
164
165
+
**Mark Types:**
166
+
167
+
- **bold**: Bold text (``<strong>``)
168
+
- **italic**: Italic text (``<em>``)
169
+
- **link**: Links (``<a>``)
170
+
- **code**: Inline code (``<code>``)
171
+
- **strike**: Strikethrough text (``<s>``)
172
+
- **underline**: Underlined text (``<u>``)
173
+
151
174
Menu Integration
152
175
----------------
153
176
154
-
When configured with CSS classes, NodeClass automatically adds context-sensitive dropdown menus to the editor. The menu options change based on the currently selected node type:
177
+
When configured with CSS classes, NodeClass automatically adds context-sensitive dropdown menus to the editor. The menu options change based on the currently selected node or mark type:
155
178
156
179
- When a paragraph is selected, only paragraph classes are shown
157
180
- When a table is selected, only table classes are shown
158
-
- When a table cell is selected, only table cell classes are shown
181
+
- When text with a bold mark is selected, bold classes are shown
182
+
- When a link is selected, link classes are shown
159
183
160
184
Each dropdown includes:
161
185
162
-
- **default**: Removes any applied node class (returns to normal styling)
163
-
- Each configured CSS class for that node type as a selectable option
186
+
- **Reset classes**: Removes any applied classes from nodes and marks (returns to normal styling)
187
+
- Each configured CSS class for the applicable types as a selectable option
164
188
165
-
The menu items appear in the ``nodeClass`` group and are contextually filtered.
189
+
The menu items appear in the ``nodeClass`` group and are contextually filtered. Mark class options are hidden when the selection is empty or when the mark type is not active in the current selection.
166
190
167
191
Commands
168
192
--------
169
193
170
-
The NodeClass extension provides these commands:
194
+
The NodeClass extension works automatically through menu integration. For marks, classes are applied using the standard mark commands:
<p>This is <strongclass="important">very important</strong> information.</p>
238
+
205
239
Sanitization
206
240
------------
207
241
208
-
When using server-side sanitization, the NodeClass extension automatically configures the sanitizer to allow ``class`` attributes on all supported block-level elements.
242
+
When using server-side sanitization, the NodeClass extension automatically configures the sanitizer to allow ``class`` attributes on all supported block-level elements and marks.
209
243
210
244
Styling Examples
211
245
----------------
212
246
213
-
Define CSS rules in your stylesheet to style the configured classes:
247
+
Define CSS rules in your stylesheet to style the configured classes for both nodes and marks:
214
248
215
249
.. code-block:: css
216
250
@@ -288,6 +322,36 @@ Define CSS rules in your stylesheet to style the configured classes:
288
322
padding-left: 1rem;
289
323
}
290
324
325
+
/* Mark classes */
326
+
.ProseMirrorstrong.emphasis {
327
+
color: #d32f2f;
328
+
font-weight: 700;
329
+
}
330
+
331
+
.ProseMirrorstrong.important {
332
+
background-color: #fff176;
333
+
padding: 00.25rem;
334
+
font-weight: 900;
335
+
}
336
+
337
+
.ProseMirrora.external::after {
338
+
content: " ↗";
339
+
font-size: 0.8em;
340
+
}
341
+
342
+
.ProseMirrora.button {
343
+
display: inline-block;
344
+
padding: 0.5rem1rem;
345
+
background-color: #2196f3;
346
+
color: white;
347
+
text-decoration: none;
348
+
border-radius: 4px;
349
+
}
350
+
351
+
.ProseMirrora.button:hover {
352
+
background-color: #1976d2;
353
+
}
354
+
291
355
/* List classes */
292
356
.ProseMirrorul.checklist {
293
357
list-style: none;
@@ -404,7 +468,12 @@ Comparison with TextClass
404
468
405
469
NodeClass complements TextClass by targeting different content levels:
406
470
407
-
- **TextClass**: Applies to inline text spans within content (``<span class="...">``)
408
-
- **NodeClass**: Applies to entire block-level elements (``<p class="...">``, ``<table class="...">``)
471
+
- **TextClass**: Applies to inline text spans using ``<span>`` tags (``<span class="...">``)
472
+
- **NodeClass**: Applies to both:
473
+
474
+
- Entire block-level elements (``<p class="...">``, ``<table class="...">``)
475
+
- Inline marks using their native tags (``<strong class="...">``, ``<a class="...">``)
476
+
477
+
Use TextClass when you need a generic ``<span>`` wrapper for styling arbitrary text, and NodeClass when you want to style specific nodes or marks with their semantic HTML tags. They can be used together for comprehensive styling control.
409
478
410
-
Use TextClass for styling words or phrases within paragraphs, and NodeClass for styling entire structural elements. They can be used together for comprehensive styling control.
479
+
**Note**: If you use the same name for both a node type and a mark type in ``cssClasses``, only the node type configuration will be recognized by the NodeClass extension.
0 commit comments