tiny-markdown-editor 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -126,6 +126,7 @@ Please note:
126
126
  | `editor` | The DOM div element which the TinyMDE DOM element will modify (get created from). The `editor` attribute can be given as either an ID or the DOM element itself (i.e., the result of a call to `document.getElementById()`). Useful when you already have references to the element even before TinyMDE creation, or when you want to keep exact ordering of the DOM element among other sibling elements. |
127
127
  | `content` | The initial content of the editor, given as a string. May contain newlines. |
128
128
  | `textarea` | The textarea that will be linked to the editor. The textarea can be given as an ID or as the DOM element itself (i.e., the result of a call to `document.getElementById()`). The content of the editor will be reflected in the value of the textarea at any given point in time. If `textarea` is given and `content` isn't, then the editor content will be initialized to the textarea's value. If `textarea` is given and `element` isn't, then the editor element will be created as the next sibling of the textarea element. |
129
+ | `customInlineGrammar` | An object containing custom inline grammar rules to extend TinyMDE's formatting capabilities. Each rule consists of a regular expression and HTML replacement string. See [Custom Inline Grammar](#custom-inline-grammar) for details. |
129
130
 
130
131
  If neither `element` not `textarea` are given, the editor element will be created as the last child element of the `body` element (probably not what you want in most cases, so you probably want to pass at least one of `element` or `textarea`).
131
132
 
@@ -161,6 +162,93 @@ If an entry of the `commands` array is an object, you can either customize one o
161
162
 
162
163
  The default array of commands is as follows: `['bold', 'italic', 'strikethrough', '|', 'code', '|', 'h1', 'h2', '|', 'ul', 'ol', '|', 'blockquote', 'hr', '|', 'insertLink', 'insertImage']`.
163
164
 
165
+ ### Custom Inline Grammar
166
+
167
+ TinyMDE supports extending its inline formatting capabilities by providing custom grammar rules when initializing the editor. This allows you to add custom formatting syntax alongside the standard Markdown formatting.
168
+
169
+ #### Basic Usage
170
+
171
+ ```javascript
172
+ const customGrammar = {
173
+ highlight: {
174
+ regexp: /^(==)([^=]+)(==)/,
175
+ replacement: '<span class="TMMark">$1</span><span class="TMHighlight">$2</span><span class="TMMark">$3</span>'
176
+ },
177
+ mention: {
178
+ regexp: /^(@[a-zA-Z0-9_]+)/,
179
+ replacement: '<span class="TMMention">$1</span>'
180
+ }
181
+ };
182
+
183
+ const editor = new TinyMDE.Editor({
184
+ element: 'editor',
185
+ customInlineGrammar: customGrammar
186
+ });
187
+ ```
188
+
189
+ #### Grammar Rule Format
190
+
191
+ Each custom grammar rule is an object with the following properties:
192
+
193
+ | Property | Description |
194
+ | -------- | ----------- |
195
+ | `regexp` | A regular expression that matches the custom syntax. Must start with `^` to match from the beginning of the string. |
196
+ | `replacement` | An HTML string that defines how the matched text should be formatted. Can use `$1`, `$2`, etc. to reference capture groups from the regexp. |
197
+
198
+ #### Example Use Cases
199
+
200
+ **Highlight text with `==text==`:**
201
+ ```javascript
202
+ highlight: {
203
+ regexp: /^(==)([^=]+)(==)/,
204
+ replacement: '<span class="TMMark">$1</span><span class="TMHighlight">$2</span><span class="TMMark">$3</span>'
205
+ }
206
+ ```
207
+
208
+ **User mentions with `@username`:**
209
+ ```javascript
210
+ mention: {
211
+ regexp: /^(@[a-zA-Z0-9_]+)/,
212
+ replacement: '<span class="TMMention">$1</span>'
213
+ }
214
+ ```
215
+
216
+ **Emoji shortcodes with `:emoji:`:**
217
+ ```javascript
218
+ emoji: {
219
+ regexp: /^(:)([a-z_]+)(:)/,
220
+ replacement: '<span class="TMMark">$1</span><span class="TMEmoji">$2</span><span class="TMMark">$3</span>'
221
+ }
222
+ ```
223
+
224
+ #### CSS Styling
225
+
226
+ Remember to add CSS styles for your custom classes:
227
+
228
+ ```css
229
+ .TMHighlight {
230
+ background-color: yellow;
231
+ font-weight: bold;
232
+ }
233
+
234
+ .TMMention {
235
+ color: #0066cc;
236
+ text-decoration: underline;
237
+ }
238
+
239
+ .TMEmoji {
240
+ font-size: 1.2em;
241
+ }
242
+ ```
243
+
244
+ #### Important Notes
245
+
246
+ - Custom grammar rules work alongside standard Markdown formatting
247
+ - Regular expressions should use `^` to match from the start of the remaining text
248
+ - Use `TMMark` class for markup characters that should be styled as formatting marks
249
+ - Custom rules are processed after built-in rules like escape, code, autolink, and html
250
+ - The grammar system supports pattern replacements (see grammar.ts for available patterns)
251
+
164
252
  ### Editor methods
165
253
 
166
254
  Here are some methods of the Editor object that might be useful in general interaction or custom CommandBar commands: