tiny-markdown-editor 0.2.6 → 0.2.8

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/lib/grammar.js ADDED
@@ -0,0 +1,311 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.commands = exports.inlineGrammar = exports.htmlBlockGrammar = exports.lineGrammar = exports.punctuationTrailing = exports.punctuationLeading = void 0;
4
+ exports.createMergedInlineGrammar = createMergedInlineGrammar;
5
+ exports.htmlescape = htmlescape;
6
+ const replacements = {
7
+ ASCIIPunctuation: /[!"#$%&'()*+,\-./:;<=>?@[\]^_`{|}~\\]/,
8
+ NotTriggerChar: /[^`_*[\]()<>!~]/,
9
+ Scheme: /[A-Za-z][A-Za-z0-9+.-]{1,31}/,
10
+ Email: /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*/, // From CommonMark spec
11
+ HTMLOpenTag: /<HTMLTagName(?:HTMLAttribute)*\s*\/?>/,
12
+ HTMLCloseTag: /<\/HTMLTagName\s*>/,
13
+ HTMLTagName: /[A-Za-z][A-Za-z0-9-]*/,
14
+ HTMLComment: /<!--(?:[^>-]|(?:[^>-](?:[^-]|-[^-])*[^-]))-->/,
15
+ HTMLPI: /<\?(?:|.|(?:[^?]|\?[^>])*)\?>/,
16
+ HTMLDeclaration: /<![A-Z]+\s[^>]*>/,
17
+ HTMLCDATA: /<!\[CDATA\[.*?\]\]>/,
18
+ HTMLAttribute: /\s+[A-Za-z_:][A-Za-z0-9_.:-]*(?:HTMLAttValue)?/,
19
+ HTMLAttValue: /\s*=\s*(?:(?:'[^']*')|(?:"[^"]*")|(?:[^\s"'=<>`]+))/,
20
+ KnownTag: /address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul/
21
+ };
22
+ // From CommonMark.js.
23
+ exports.punctuationLeading = new RegExp(/^(?:[!"#$%&'()*+,\-./:;<=>?@[\]\\^_`{|}~\xA1\xA7\xAB\xB6\xB7\xBB\xBF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u0AF0\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166D\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2308-\u230B\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E42\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]|\uD800[\uDD00-\uDD02\uDF9F\uDFD0]|\uD801\uDD6F|\uD802[\uDC57\uDD1F\uDD3F\uDE50-\uDE58\uDE7F\uDEF0-\uDEF6\uDF39-\uDF3F\uDF99-\uDF9C]|\uD804[\uDC47-\uDC4D\uDCBB\uDCBC\uDCBE-\uDCC1\uDD40-\uDD43\uDD74\uDD75\uDDC5-\uDDC9\uDDCD\uDDDB\uDDDD-\uDDDF\uDE38-\uDE3D\uDEA9]|\uD805[\uDCC6\uDDC1-\uDDD7\uDE41-\uDE43\uDF3C-\uDF3E]|\uD809[\uDC70-\uDC74]|\uD81A[\uDE6E\uDE6F\uDEF5\uDF37-\uDF3B\uDF44]|\uD82F\uDC9F|\uD836[\uDE87-\uDE8B])/);
24
+ exports.punctuationTrailing = new RegExp(/(?:[!"#$%&'()*+,\-./:;<=>?@[\]\\^_`{|}~\xA1\xA7\xAB\xB6\xB7\xBB\xBF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u0AF0\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166D\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2308-\u230B\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E42\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]|\uD800[\uDD00-\uDD02\uDF9F\uDFD0]|\uD801\uDD6F|\uD802[\uDC57\uDD1F\uDD3F\uDE50-\uDE58\uDE7F\uDEF0-\uDEF6\uDF39-\uDF3F\uDF99-\uDF9C]|\uD804[\uDC47-\uDC4D\uDCBB\uDCBC\uDCBE-\uDCC1\uDD40-\uDD43\uDD74\uDD75\uDDC5-\uDDC9\uDDCD\uDDDB\uDDDD-\uDDDF\uDE38-\uDE3D\uDEA9]|\uD805[\uDCC6\uDDC1-\uDDD7\uDE41-\uDE43\uDF3C-\uDF3E]|\uD809[\uDC70-\uDC74]|\uD81A[\uDE6E\uDE6F\uDEF5\uDF37-\uDF3B\uDF44]|\uD82F\uDC9F|\uD836[\uDE87-\uDE8B])$/);
25
+ /**
26
+ * This is CommonMark's block grammar, but we're ignoring nested blocks here.
27
+ */
28
+ exports.lineGrammar = {
29
+ TMH1: {
30
+ regexp: /^( {0,3}#\s)(.*?)((?:\s+#+\s*)?)$/,
31
+ replacement: '<span class="TMMark TMMark_TMH1">$1</span>$$2<span class="TMMark TMMark_TMH1">$3</span>'
32
+ },
33
+ TMH2: {
34
+ regexp: /^( {0,3}##\s)(.*?)((?:\s+#+\s*)?)$/,
35
+ replacement: '<span class="TMMark TMMark_TMH2">$1</span>$$2<span class="TMMark TMMark_TMH2">$3</span>'
36
+ },
37
+ TMH3: {
38
+ regexp: /^( {0,3}###\s)(.*?)((?:\s+#+\s*)?)$/,
39
+ replacement: '<span class="TMMark TMMark_TMH3">$1</span>$$2<span class="TMMark TMMark_TMH3">$3</span>'
40
+ },
41
+ TMH4: {
42
+ regexp: /^( {0,3}####\s)(.*?)((?:\s+#+\s*)?)$/,
43
+ replacement: '<span class="TMMark TMMark_TMH4">$1</span>$$2<span class="TMMark TMMark_TMH4">$3</span>'
44
+ },
45
+ TMH5: {
46
+ regexp: /^( {0,3}#####\s)(.*?)((?:\s+#+\s*)?)$/,
47
+ replacement: '<span class="TMMark TMMark_TMH5">$1</span>$$2<span class="TMMark TMMark_TMH5">$3</span>'
48
+ },
49
+ TMH6: {
50
+ regexp: /^( {0,3}######\s)(.*?)((?:\s+#+\s*)?)$/,
51
+ replacement: '<span class="TMMark TMMark_TMH6">$1</span>$$2<span class="TMMark TMMark_TMH6">$3</span>'
52
+ },
53
+ TMBlockquote: {
54
+ regexp: /^( {0,3}>[ ]?)(.*)$/,
55
+ replacement: '<span class="TMMark TMMark_TMBlockquote">$1</span>$$2'
56
+ },
57
+ TMCodeFenceBacktickOpen: {
58
+ regexp: /^( {0,3}(?<seq>````*)\s*)([^`]*?)(\s*)$/,
59
+ replacement: '<span class="TMMark TMMark_TMCodeFenceBacktick">$1</span><span class="TMInfoString">$3</span>$4'
60
+ },
61
+ TMCodeFenceTildeOpen: {
62
+ regexp: /^( {0,3}(?<seq>~~~~*)\s*)(.*?)(\s*)$/,
63
+ replacement: '<span class="TMMark TMMark_TMCodeFenceTilde">$1</span><span class="TMInfoString">$3</span>$4'
64
+ },
65
+ TMCodeFenceBacktickClose: {
66
+ regexp: /^( {0,3}(?<seq>````*))(\s*)$/,
67
+ replacement: '<span class="TMMark TMMark_TMCodeFenceBacktick">$1</span>$3'
68
+ },
69
+ TMCodeFenceTildeClose: {
70
+ regexp: /^( {0,3}(?<seq>~~~~*))(\s*)$/,
71
+ replacement: '<span class="TMMark TMMark_TMCodeFenceTilde">$1</span>$3'
72
+ },
73
+ TMBlankLine: {
74
+ regexp: /^([ \t]*)$/,
75
+ replacement: '$0'
76
+ },
77
+ TMSetextH1Marker: {
78
+ regexp: /^ {0,3}=+\s*$/,
79
+ replacement: '<span class="TMMark TMMark_TMSetextH1Marker">$0</span>'
80
+ },
81
+ TMSetextH2Marker: {
82
+ regexp: /^ {0,3}-+\s*$/,
83
+ replacement: '<span class="TMMark TMMark_TMSetextH1Marker">$0</span>'
84
+ },
85
+ TMHR: {
86
+ regexp: /^( {0,3}(\*[ \t]*\*[ \t]*\*[ \t*]*)|(-[ \t]*-[ \t]*-[ \t-]*)|(_[ \t]*_[ \t]*_[ \t_]*))$/,
87
+ replacement: '<span class="TMMark TMMark_TMHR">$0</span>'
88
+ },
89
+ TMUL: {
90
+ regexp: /^( {0,3}[+*-] {1,4})(.*)$/,
91
+ replacement: '<span class="TMMark TMMark_TMUL">$1</span>$$2'
92
+ },
93
+ TMOL: {
94
+ regexp: /^( {0,3}\d{1,9}[.)] {1,4})(.*)$/,
95
+ replacement: '<span class="TMMark TMMark_TMOL">$1</span>$$2'
96
+ },
97
+ // TODO: This is currently preventing sublists (and any content within list items, really) from working
98
+ TMIndentedCode: {
99
+ regexp: /^( {4}|\t)(.*)$/,
100
+ replacement: '<span class="TMMark TMMark_TMIndentedCode">$1</span>$2'
101
+ },
102
+ TMLinkReferenceDefinition: {
103
+ // TODO: Link destination can't include unbalanced parantheses, but we just ignore that here
104
+ regexp: /^( {0,3}\[\s*)([^\s\]](?:[^\]]|\\\])*?)(\s*\]:\s*)((?:[^\s<>]+)|(?:<(?:[^<>\\]|\\.)*>))?(\s*)((?:\((?:[^()\\]|\\.)*\))|(?:"(?:[^"\\]|\\.)*")|(?:'(?:[^'\\]|\\.)*'))?(\s*)$/,
105
+ replacement: '<span class="TMMark TMMark_TMLinkReferenceDefinition">$1</span><span class="TMLinkLabel TMLinkLabel_Definition">$2</span><span class="TMMark TMMark_TMLinkReferenceDefinition">$3</span><span class="TMLinkDestination">$4</span>$5<span class="TMLinkTitle">$6</span>$7',
106
+ labelPlaceholder: 2, // this defines which placeholder in the above regex is the link "label"
107
+ },
108
+ };
109
+ /**
110
+ * HTML blocks have multiple different classes of opener and closer. This array defines all the cases
111
+ */
112
+ exports.htmlBlockGrammar = [
113
+ { start: /^ {0,3}<(?:script|pre|style)(?:\s|>|$)/i, end: /(?:<\/script>|<\/pre>|<\/style>)/i, paraInterrupt: true },
114
+ { start: /^ {0,3}<!--/, end: /-->/, paraInterrupt: true },
115
+ { start: /^ {0,3}<\?/, end: /\?>/, paraInterrupt: true },
116
+ { start: /^ {0,3}<![A-Z]/, end: />/, paraInterrupt: true },
117
+ { start: /^ {0,3}<!\[CDATA\[/, end: /\]\]>/, paraInterrupt: true },
118
+ { start: /^ {0,3}(?:<|<\/)(?:KnownTag)(?:\s|>|\/>|$)/i, end: false, paraInterrupt: true },
119
+ { start: /^ {0,3}(?:HTMLOpenTag|HTMLCloseTag)\s*$/, end: false, paraInterrupt: false },
120
+ ];
121
+ /**
122
+ * Structure of the object:
123
+ * Top level entries are rules, each consisting of a regular expressions (in string format) as well as a replacement.
124
+ * In the regular expressions, replacements from the object 'replacements' will be processed before compiling into the property regexp.
125
+ */
126
+ exports.inlineGrammar = {
127
+ escape: {
128
+ regexp: /^\\(ASCIIPunctuation)/,
129
+ replacement: '<span class="TMMark TMMark_TMEscape">\\</span>$1'
130
+ },
131
+ code: {
132
+ regexp: /^(`+)((?:[^`])|(?:[^`].*?[^`]))(\1)/,
133
+ replacement: '<span class="TMMark TMMark_TMCode">$1</span><code class="TMCode">$2</code><span class="TMMark TMMark_TMCode">$3</span>'
134
+ },
135
+ autolink: {
136
+ regexp: /^<((?:Scheme:[^\s<>]*)|(?:Email))>/,
137
+ replacement: '<span class="TMMark TMMark_TMAutolink">&lt;</span><span class="TMAutolink">$1</span><span class="TMMark TMMark_TMAutolink">&gt;</span>'
138
+ },
139
+ html: {
140
+ regexp: /^((?:HTMLOpenTag)|(?:HTMLCloseTag)|(?:HTMLComment)|(?:HTMLPI)|(?:HTMLDeclaration)|(?:HTMLCDATA))/,
141
+ replacement: '<span class="TMHTML">$1</span>',
142
+ },
143
+ linkOpen: {
144
+ regexp: /^\[/,
145
+ replacement: ''
146
+ },
147
+ imageOpen: {
148
+ regexp: /^!\[/,
149
+ replacement: ''
150
+ },
151
+ linkLabel: {
152
+ regexp: /^(\[\s*)([^\]]*?)(\s*\])/,
153
+ replacement: '',
154
+ labelPlaceholder: 2
155
+ },
156
+ default: {
157
+ regexp: /^(.|(?:NotTriggerChar+))/,
158
+ replacement: '$1'
159
+ }
160
+ };
161
+ // Process replacements in regexps
162
+ const replacementRegexp = new RegExp(Object.keys(replacements).join('|'));
163
+ // Inline
164
+ const inlineRules = [...Object.keys(exports.inlineGrammar)];
165
+ for (let rule of inlineRules) {
166
+ let re = exports.inlineGrammar[rule].regexp.source;
167
+ // Replace while there is something to replace. This means it also works over multiple levels (replacements containing replacements)
168
+ while (re.match(replacementRegexp)) {
169
+ re = re.replace(replacementRegexp, (string) => { return replacements[string].source; });
170
+ }
171
+ exports.inlineGrammar[rule].regexp = new RegExp(re, exports.inlineGrammar[rule].regexp.flags);
172
+ }
173
+ // HTML Block (only opening rule is processed currently)
174
+ for (let rule of exports.htmlBlockGrammar) {
175
+ let re = rule.start.source;
176
+ // Replace while there is something to replace. This means it also works over multiple levels (replacements containing replacements)
177
+ while (re.match(replacementRegexp)) {
178
+ re = re.replace(replacementRegexp, (string) => { return replacements[string].source; });
179
+ }
180
+ rule.start = new RegExp(re, rule.start.flags);
181
+ }
182
+ /**
183
+ * Creates a merged inline grammar by combining the default inline grammar with custom rules.
184
+ * Custom rules are processed and their regexp patterns are expanded with replacements.
185
+ * @param customRules - Object containing custom inline grammar rules
186
+ * @returns Merged inline grammar object
187
+ */
188
+ function createMergedInlineGrammar(customRules = {}) {
189
+ const merged = { ...exports.inlineGrammar };
190
+ // Process custom rules
191
+ for (const [ruleName, rule] of Object.entries(customRules)) {
192
+ // Copy the rule to avoid modifying the original
193
+ const processedRule = { ...rule };
194
+ // Process replacements in the regexp
195
+ let regexpSource = rule.regexp.source;
196
+ const replacementRegexp = new RegExp(Object.keys(replacements).join('|'));
197
+ // Replace while there is something to replace
198
+ while (regexpSource.match(replacementRegexp)) {
199
+ regexpSource = regexpSource.replace(replacementRegexp, (match) => {
200
+ return replacements[match].source;
201
+ });
202
+ }
203
+ processedRule.regexp = new RegExp(regexpSource, rule.regexp.flags);
204
+ merged[ruleName] = processedRule;
205
+ }
206
+ return merged;
207
+ }
208
+ /**
209
+ * Escapes HTML special characters (<, >, and &) in the string.
210
+ * @param {string} string The raw string to be escaped
211
+ * @returns {string} The string, ready to be used in HTML
212
+ */
213
+ function htmlescape(string) {
214
+ return (string ? string : '')
215
+ .replace(/&/g, '&amp;')
216
+ .replace(/</g, '&lt;')
217
+ .replace(/>/g, '&gt;');
218
+ }
219
+ /**
220
+ * Contains the commands that can be sent to the editor. Contains objects with a name representing the name of the command.
221
+ * Each of the objects contains the following keys:
222
+ *
223
+ * - type: Can be either inline (for inline formatting) or line (for block / line formatting).
224
+ * - className: Used to determine whether the command is active at a given position.
225
+ * For line formatting, this looks at the class of the line element. For inline elements, tries to find an enclosing element with that class.
226
+ * - set / unset: Contain instructions how to set and unset the command. For line type commands, both consist of a pattern and replacement that
227
+ * will be applied to each line (using String.replace). For inline type commands, the set object contains a pre and post string which will
228
+ * be inserted before and after the selection. The unset object contains a prePattern and a postPattern. Both should be regular expressions and
229
+ * they will be applied to the portion of the line before and after the selection (using String.replace, with an empty replacement string).
230
+ */
231
+ exports.commands = {
232
+ // Replacements for unset for inline commands are '' by default
233
+ bold: {
234
+ type: 'inline',
235
+ className: 'TMStrong',
236
+ set: { pre: '**', post: '**' },
237
+ unset: { prePattern: /(?:\*\*|__)$/, postPattern: /^(?:\*\*|__)/ }
238
+ },
239
+ italic: {
240
+ type: 'inline',
241
+ className: 'TMEm',
242
+ set: { pre: '*', post: '*' },
243
+ unset: { prePattern: /(?:\*|_)$/, postPattern: /^(?:\*|_)/ }
244
+ },
245
+ code: {
246
+ type: 'inline',
247
+ className: 'TMCode',
248
+ set: { pre: '`', post: '`' },
249
+ unset: { prePattern: /`+$/, postPattern: /^`+/ } // FIXME this doesn't ensure balanced backticks right now
250
+ },
251
+ strikethrough: {
252
+ type: 'inline',
253
+ className: 'TMStrikethrough',
254
+ set: { pre: '~~', post: '~~' },
255
+ unset: { prePattern: /~~$/, postPattern: /^~~/ }
256
+ },
257
+ h1: {
258
+ type: 'line',
259
+ className: 'TMH1',
260
+ set: { pattern: /^( {0,3}(?:(?:#+|[0-9]{1,9}[).]|[>\-*+])\s+)?)(.*)$/, replacement: '# $2' },
261
+ unset: { pattern: /^( {0,3}#\s+)(.*?)((?:\s+#+\s*)?)$/, replacement: '$2' }
262
+ },
263
+ h2: {
264
+ type: 'line',
265
+ className: 'TMH2',
266
+ set: { pattern: /^( {0,3}(?:(?:#+|[0-9]{1,9}[).]|[>\-*+])\s+)?)(.*)$/, replacement: '## $2' },
267
+ unset: { pattern: /^( {0,3}##\s+)(.*?)((?:\s+#+\s*)?)$/, replacement: '$2' }
268
+ },
269
+ h3: {
270
+ type: 'line',
271
+ className: 'TMH3',
272
+ set: { pattern: /^( {0,3}(?:(?:#+|[0-9]{1,9}[).]|[>\-*+])\s+)?)(.*)$/, replacement: '### $2' },
273
+ unset: { pattern: /^( {0,3}###\s+)(.*?)((?:\s+#+\s*)?)$/, replacement: '$2' }
274
+ },
275
+ h4: {
276
+ type: 'line',
277
+ className: 'TMH4',
278
+ set: { pattern: /^( {0,3}(?:(?:#+|[0-9]{1,9}[).]|[>\-*+])\s+)?)(.*)$/, replacement: '#### $2' },
279
+ unset: { pattern: /^( {0,3}####\s+)(.*?)((?:\s+#+\s*)?)$/, replacement: '$2' }
280
+ },
281
+ h5: {
282
+ type: 'line',
283
+ className: 'TMH5',
284
+ set: { pattern: /^( {0,3}(?:(?:#+|[0-9]{1,9}[).]|[>\-*+])\s+)?)(.*)$/, replacement: '##### $2' },
285
+ unset: { pattern: /^( {0,3}#####\s+)(.*?)((?:\s+#+\s*)?)$/, replacement: '$2' }
286
+ },
287
+ h6: {
288
+ type: 'line',
289
+ className: 'TMH6',
290
+ set: { pattern: /^( {0,3}(?:(?:#+|[0-9]{1,9}[).]|[>\-*+])\s+)?)(.*)$/, replacement: '###### $2' },
291
+ unset: { pattern: /^( {0,3}######\s+)(.*?)((?:\s+#+\s*)?)$/, replacement: '$2' }
292
+ },
293
+ ul: {
294
+ type: 'line',
295
+ className: 'TMUL',
296
+ set: { pattern: /^( {0,3}(?:(?:#+|[0-9]{1,9}[).]|[>\-*+])\s+)?)(.*)$/, replacement: '- $2' },
297
+ unset: { pattern: /^( {0,3}[+*-] {1,4})(.*)$/, replacement: '$2' }
298
+ },
299
+ ol: {
300
+ type: 'line',
301
+ className: 'TMOL',
302
+ set: { pattern: /^( {0,3}(?:(?:#+|[0-9]{1,9}[).]|[>\-*+])\s+)?)(.*)$/, replacement: '$#. $2' },
303
+ unset: { pattern: /^( {0,3}\d{1,9}[.)] {1,4})(.*)$/, replacement: '$2' }
304
+ },
305
+ blockquote: {
306
+ type: 'line',
307
+ className: 'TMBlockquote',
308
+ set: { pattern: /^( {0,3}(?:(?:#+|[0-9]{1,9}[).]|[>\-*+])\s+)?)(.*)$/, replacement: '> $2' },
309
+ unset: { pattern: /^( {0,3}>[ ]?)(.*)$/, replacement: '$2' }
310
+ },
311
+ };
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import CommandBar from "./TinyMDECommandBar";
2
+ import Editor from "./TinyMDE";
3
+ export { Editor, CommandBar };
package/lib/index.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CommandBar = exports.Editor = void 0;
7
+ const TinyMDECommandBar_1 = __importDefault(require("./TinyMDECommandBar"));
8
+ exports.CommandBar = TinyMDECommandBar_1.default;
9
+ const TinyMDE_1 = __importDefault(require("./TinyMDE"));
10
+ exports.Editor = TinyMDE_1.default;
@@ -0,0 +1,2 @@
1
+ declare const svg: Record<string, string>;
2
+ export default svg;
package/lib/svg/svg.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const svg = {
4
+ blockquote: `<svg height="18" width="18"><rect width="5" height="5" x="3" y="4" ry="1"/><rect ry="1" y="4" x="10" height="5" width="5"/><path d="M8 6.999v3c0 1-1 3-1 3s-.331 1-1.331 1h-1c-1 0-.669-1-.669-1s1-2 1-3v-3zm7 0v3c0 1-1 3-1 3s-.331 1-1.331 1h-1c-1 0-.669-1-.669-1s1-2 1-3v-3z"/></svg>`,
5
+ bold: `<svg height="18" width="18"><path d="M4 2a1 1 0 00-1 1v12a1 1 0 001 1h6c4 0 5-2 5-4 0-1.322-.434-2.636-1.885-3.381C13.772 7.885 14 6.945 14 6c0-2-1-4-5-4zm1 2h4c1.668 0 2.32.393 2.6.672.28.279.4.662.4 1.328s-.12 1.057-.4 1.338c-.275.274-1.014.646-2.6.662H5zm5 6c1.666.005 2.318.388 2.596.666.277.278.404.667.404 1.334s-.127 1.06-.404 1.338c-.278.278-.93.66-2.596.662l-4.992.004L5 10z"/></svg>`,
6
+ clear_formatting: `<svg height="18" width="18"><path d="M11.03 1a1 1 0 00-.74.3l-9 9a1 1 0 000 1.4l4 4A1 1 0 006 16h2a1 1 0 00.7-.3l8-8a1 1 0 000-1.4l-5-5a1 1 0 00-.67-.3zM8.7 5.7l3.58 3.6L7.6 14H6.4l-3-3 5.3-5.3z"/><rect ry=".8" rx=".8" y="14" x="16" height="2" width="2"/><rect width="2" height="2" x="13" y="14" rx=".8" ry=".8"/><rect ry=".8" rx=".8" y="14" x="10" height="2" width="2"/></svg>`,
7
+ code: `<svg height="18" width="18"><path d="M13.5 2.994a.5.5 0 00-.5.5.5.5 0 000 .034V4.53a5.993 5.993 0 00-7.451-.445A6 6 0 1012.45 13.9a5.99 5.99 0 001.346-1.334.5.5 0 00.096-.101.5.5 0 00-.12-.698.5.5 0 00-.697.12l-.004-.005a5 5 0 01-1.197 1.2 5 5 0 111.215-6.965.5.5 0 00.697.12.5.5 0 00.211-.44V4.745H14V3.493a.5.5 0 00-.5-.5z"/></svg>`,
8
+ h1: `<svg height="18" width="18"><path d="M3 2s0-1 1-1h1c1 0 1 1 1 1v6h6V2s0-1 1-1h1c1 0 1 1 1 1v14s0 1-1 1h-1c-1 0-1-1-1-1v-6H6v6s0 1-1 1H4c-1 0-1-1-1-1z"/></svg>`,
9
+ h2: `<svg height="18" width="18"><path d="M4 2s0-1 1-1 1 1 1 1v6c1-1 2-1 4-1 3 0 4 2 4 4v5s0 1-1 1-1-1-1-1v-5c0-1.094-1-2-2-2-2 0-3 0-4 2v5s0 1-1 1-1-1-1-1z"/></svg>`,
10
+ hr: `<svg height="18" width="18"><rect ry="1" y="8" height="2" width="18" style="font-variation-settings:normal;marker:none"/></svg>`,
11
+ image: `<svg height="18" width="18"><path d="M1 2v14h16V2H1zm2 2h12v7l-3-3-4 4-2-2-3 3V4z"/><circle r="1.5" cy="6.5" cx="5.5"/></svg>`,
12
+ italic: `<svg height="18" width="18"><path d="M9 2a1 1 0 000 2L7 14a1 1 0 100 2h2a1 1 0 000-2l2-10a1 1 0 100-2z"/></svg>`,
13
+ link: `<svg height="18" width="18"><path d="M9.07 5.18a3.9 3.9 0 00-1.52.43C6.31 6.22 5.3 7.29 4.3 8.29c-1 1-2.07 2.02-2.68 3.26-.31.62-.5 1.33-.41 2.07.09.75.48 1.47 1.1 2.09.61.61 1.33 1 2.08 1.1.74.09 1.45-.1 2.07-.42 1.24-.61 2.26-1.68 3.26-2.68.46-.47.94-.94 1.39-1.44l-.43.26c-.68.34-1.49.56-2.36.46-.2-.03-.4-.08-.6-.14-.79.76-1.55 1.45-2.16 1.76-.38.19-.67.24-.92.21-.26-.03-.54-.14-.92-.53-.39-.38-.5-.66-.53-.91-.03-.26.02-.55.21-.93.39-.76 1.32-1.74 2.32-2.74 1-1 1.98-1.93 2.74-2.32.38-.19.67-.24.93-.21.25.03.53.14.91.53.39.38.5.66.53.92v.06l1.12-1.06.44-.47c-.18-.3-.4-.6-.67-.87-.62-.61-1.34-1-2.09-1.1a3.08 3.08 0 00-.55-.01z"/><path d="M13.07.86a3.9 3.9 0 00-1.52.43c-1.24.62-2.26 1.69-3.26 2.69-.46.47-.94.94-1.39 1.43.15-.08.28-.18.43-.25a4.4 4.4 0 012.36-.46c.2.02.4.07.6.14.79-.77 1.55-1.46 2.16-1.76.38-.19.67-.25.93-.21.25.03.53.14.91.52.39.38.5.66.53.92.03.26-.02.55-.21.93-.39.76-1.32 1.74-2.32 2.74-1 1-1.98 1.93-2.74 2.31-.38.2-.67.25-.93.22-.25-.04-.53-.15-.91-.53-.39-.38-.5-.66-.53-.92V9c-.36.33-.73.67-1.12 1.06l-.43.46c.17.3.4.6.66.87.62.62 1.34 1 2.08 1.1.75.1 1.46-.1 2.08-.41 1.24-.62 2.26-1.69 3.26-2.69s2.07-2.02 2.68-3.26c.31-.62.5-1.32.41-2.07a3.63 3.63 0 00-1.1-2.08c-.61-.62-1.33-1-2.07-1.1a3.08 3.08 0 00-.56-.02z"/></svg>`,
14
+ ol: `<svg height="18" width="18"><path d="M1.5 7a.5.5 0 100 1h1a.5.5 0 01.5.5c0 .164-.08.31-.14.355l-1.655 1.25A.492.492 0 001 10.5a.5.5 0 00.5.5h2a.5.5 0 000-1H3l.398-.299A1.5 1.5 0 002.5 7z"/><path d="M1.5 12c-.667 0-.667 1 0 1h1.25c.333 0 .333.5 0 .5H2.5c-.667 0-.667 1 0 1h.25c.333 0 .333.5 0 .5H1.5c-.667 0-.667 1 0 1h1c.398 0 .78-.131 1.06-.365.282-.235.44-.554.44-.885a1.121 1.121 0 00-.303-.75c.191-.204.3-.47.303-.75 0-.332-.158-.651-.44-.885-.3-.241-.675-.37-1.06-.365z"/><rect y="13" x="6" height="2" width="12" ry="1"/><rect ry="1" width="12" height="2" x="6" y="8"/><rect y="3" x="6" height="2" width="12" ry="1"/><path d="M1.5 2a.5.5 0 100 1H2v2h-.5a.5.5 0 100 1h2a.5.5 0 100-1H3V2.5c0-.277-.223-.5-.5-.5z"/></svg>`,
15
+ redo: `<svg height="18" width="18"><path d="M 7.2695308,2.7050781 C 8.1128755,2.7081581 8.9529895,2.8712156 9.730469,3.1347656 11.408874,3.7037121 12.90142,4.6847104 14,5.6367188 V 4 h 2 V 9 H 11 V 7 h 1.509765 C 11.59075,6.2485173 10.340208,5.453808 9.0878904,5.0292969 7.4309398,4.4676231 5.9453458,4.468717 4.7070308,5.7070312 c -1.225014,1.2250142 -1.409769,2.7206953 -0.779297,4.2968748 0.630472,1.57618 2.167475,3.158006 4.4433598,4.06836 l -0.7421878,1.855468 c -2.724115,-1.089646 -4.687112,-3.00782 -5.55664,-5.18164 -0.869528,-2.1738206 -0.554283,-4.6781393 1.220703,-6.4531252 0.923857,-0.9238568 2.015388,-1.388828 3.134765,-1.5351563 0.279845,-0.036582 0.560682,-0.053761 0.841797,-0.052734 z" /></svg>`,
16
+ strikethrough: `<svg width="18" height="18"><path d="M10 2C6 2 4 4 4 6c0 .338.08.672.193 1h2.34C6.113 6.629 6 6.295 6 6c0-.334.117-.725.691-1.154C7.265 4.416 8.331 4 10 4h3a1 1 0 000-2zm1.477 9c.413.368.523.706.523 1 0 .334-.127.712-.701 1.143-.575.43-1.632.85-3.299.857l-1.006.007V14H5a1 1 0 000 2h3c4 0 6-2 6-4 0-.338-.081-.672-.195-1z"/><rect ry="1" y="8" x="1" height="2" width="16"/></svg>`,
17
+ ul: `<svg height="18" width="18"><circle cx="2" cy="9" r="2"/><circle cy="4" cx="2" r="2"/><rect y="3" x="6" height="2" width="12" ry="1"/><circle cx="2" cy="14" r="2"/><rect ry="1" width="12" height="2" x="6" y="8"/><rect y="13" x="6" height="2" width="12" ry="1"/></svg>`,
18
+ undo: `<svg height="18" width="18"><path d="M 10.730469 2.7050781 C 9.8871243 2.7081594 9.0470103 2.8712156 8.2695312 3.1347656 C 6.5911256 3.7037121 5.0985797 4.6847104 4 5.6367188 L 4 4 L 2 4 L 2 9 L 7 9 L 7 7 L 5.4902344 7 C 6.4092499 6.2485173 7.6597914 5.453808 8.9121094 5.0292969 C 10.56906 4.4676231 12.054654 4.468717 13.292969 5.7070312 C 14.517983 6.9320454 14.702738 8.4277265 14.072266 10.003906 C 13.441794 11.580086 11.904791 13.161912 9.6289062 14.072266 L 10.371094 15.927734 C 13.095209 14.838088 15.058206 12.919914 15.927734 10.746094 C 16.797262 8.5722734 16.482017 6.0679547 14.707031 4.2929688 C 13.783174 3.369112 12.691643 2.9041408 11.572266 2.7578125 C 11.292421 2.7212304 11.011584 2.704051 10.730469 2.7050781 z " /></svg>
19
+ `
20
+ };
21
+ exports.default = svg;
package/lib/tiny.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import Editor from "./TinyMDE";
2
+ export { Editor };
package/lib/tiny.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Editor = void 0;
7
+ const TinyMDE_1 = __importDefault(require("./TinyMDE"));
8
+ exports.Editor = TinyMDE_1.default;
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "tiny-markdown-editor",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "TinyMDE: A tiny, ultra low dependency, embeddable HTML/JavaScript Markdown editor.",
5
5
  "main": "lib/index.js",
6
6
  "files": [
7
7
  "dist/*",
8
- "lib/*",
8
+ "lib/**/*.js",
9
9
  "lib/**/*.d.ts"
10
10
  ],
11
11
  "types": "lib/index.d.ts",
@@ -16,6 +16,7 @@
16
16
  ],
17
17
  "scripts": {
18
18
  "test": "npx gulp && npx jest",
19
+ "typecheck": "npx tsc --noEmit",
19
20
  "test:chromium": "npx gulp && npx jest --selectProjects chromium",
20
21
  "test:firefox": "npx gulp && npx jest --selectProjects firefox",
21
22
  "test:webkit": "npx gulp && npx jest --selectProjects webkit",