overtype 2.0.6 → 2.1.0
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 +34 -3
- package/dist/overtype-webcomponent.esm.js +88 -2
- package/dist/overtype-webcomponent.esm.js.map +2 -2
- package/dist/overtype-webcomponent.js +88 -2
- package/dist/overtype-webcomponent.js.map +2 -2
- package/dist/overtype-webcomponent.min.js +40 -40
- package/dist/overtype.cjs +88 -2
- package/dist/overtype.cjs.map +2 -2
- package/dist/overtype.esm.js +88 -2
- package/dist/overtype.esm.js.map +2 -2
- package/dist/overtype.js +90 -3
- package/dist/overtype.js.map +2 -2
- package/dist/overtype.min.js +11 -10
- package/package.json +5 -3
- package/src/overtype.js +73 -1
- package/src/parser.js +25 -2
package/dist/overtype.js
CHANGED
|
@@ -53,6 +53,24 @@ var OverType = (() => {
|
|
|
53
53
|
static setCodeHighlighter(highlighter) {
|
|
54
54
|
this.codeHighlighter = highlighter;
|
|
55
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Set custom syntax processor function
|
|
58
|
+
* @param {Function|null} processor - Function that takes (html) and returns modified HTML
|
|
59
|
+
*/
|
|
60
|
+
static setCustomSyntax(processor) {
|
|
61
|
+
this.customSyntax = processor;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Apply custom syntax processor to parsed HTML
|
|
65
|
+
* @param {string} html - Parsed HTML line
|
|
66
|
+
* @returns {string} HTML with custom syntax applied
|
|
67
|
+
*/
|
|
68
|
+
static applyCustomSyntax(html) {
|
|
69
|
+
if (this.customSyntax) {
|
|
70
|
+
return this.customSyntax(html);
|
|
71
|
+
}
|
|
72
|
+
return html;
|
|
73
|
+
}
|
|
56
74
|
/**
|
|
57
75
|
* Escape HTML special characters
|
|
58
76
|
* @param {string} text - Raw text to escape
|
|
@@ -391,14 +409,14 @@ var OverType = (() => {
|
|
|
391
409
|
const codeFenceRegex = /^```[^`]*$/;
|
|
392
410
|
if (codeFenceRegex.test(line)) {
|
|
393
411
|
inCodeBlock = !inCodeBlock;
|
|
394
|
-
return this.parseLine(line, isPreviewMode);
|
|
412
|
+
return this.applyCustomSyntax(this.parseLine(line, isPreviewMode));
|
|
395
413
|
}
|
|
396
414
|
if (inCodeBlock) {
|
|
397
415
|
const escaped = this.escapeHtml(line);
|
|
398
416
|
const indented = this.preserveIndentation(escaped, line);
|
|
399
417
|
return `<div>${indented || " "}</div>`;
|
|
400
418
|
}
|
|
401
|
-
return this.parseLine(line, isPreviewMode);
|
|
419
|
+
return this.applyCustomSyntax(this.parseLine(line, isPreviewMode));
|
|
402
420
|
});
|
|
403
421
|
const html = parsedLines.join("");
|
|
404
422
|
return this.postProcessHTML(html, instanceHighlighter);
|
|
@@ -730,6 +748,8 @@ var OverType = (() => {
|
|
|
730
748
|
__publicField(MarkdownParser, "linkIndex", 0);
|
|
731
749
|
// Global code highlighter function
|
|
732
750
|
__publicField(MarkdownParser, "codeHighlighter", null);
|
|
751
|
+
// Custom syntax processor function
|
|
752
|
+
__publicField(MarkdownParser, "customSyntax", null);
|
|
733
753
|
/**
|
|
734
754
|
* List pattern definitions
|
|
735
755
|
*/
|
|
@@ -4110,6 +4130,8 @@ ${blockSuffix}` : suffix;
|
|
|
4110
4130
|
this.statsBar.className = "overtype-stats";
|
|
4111
4131
|
this.container.appendChild(this.statsBar);
|
|
4112
4132
|
this._updateStats();
|
|
4133
|
+
} else if (show && this.statsBar) {
|
|
4134
|
+
this._updateStats();
|
|
4113
4135
|
} else if (!show && this.statsBar) {
|
|
4114
4136
|
this.statsBar.remove();
|
|
4115
4137
|
this.statsBar = null;
|
|
@@ -4178,6 +4200,44 @@ ${blockSuffix}` : suffix;
|
|
|
4178
4200
|
static init(target, options = {}) {
|
|
4179
4201
|
return new _OverType(target, options);
|
|
4180
4202
|
}
|
|
4203
|
+
/**
|
|
4204
|
+
* Initialize editors with options from data-ot-* attributes
|
|
4205
|
+
* @param {string} selector - CSS selector for target elements
|
|
4206
|
+
* @param {Object} defaults - Default options (data attrs override these)
|
|
4207
|
+
* @returns {Array<OverType>} Array of OverType instances
|
|
4208
|
+
* @example
|
|
4209
|
+
* // HTML: <div class="editor" data-ot-toolbar="true" data-ot-theme="cave"></div>
|
|
4210
|
+
* OverType.initFromData('.editor', { fontSize: '14px' });
|
|
4211
|
+
*/
|
|
4212
|
+
static initFromData(selector, defaults = {}) {
|
|
4213
|
+
const elements = document.querySelectorAll(selector);
|
|
4214
|
+
return Array.from(elements).map((el) => {
|
|
4215
|
+
const options = { ...defaults };
|
|
4216
|
+
for (const attr of el.attributes) {
|
|
4217
|
+
if (attr.name.startsWith("data-ot-")) {
|
|
4218
|
+
const kebab = attr.name.slice(8);
|
|
4219
|
+
const key = kebab.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
4220
|
+
options[key] = _OverType._parseDataValue(attr.value);
|
|
4221
|
+
}
|
|
4222
|
+
}
|
|
4223
|
+
return new _OverType(el, options);
|
|
4224
|
+
});
|
|
4225
|
+
}
|
|
4226
|
+
/**
|
|
4227
|
+
* Parse a data attribute value to the appropriate type
|
|
4228
|
+
* @private
|
|
4229
|
+
*/
|
|
4230
|
+
static _parseDataValue(value) {
|
|
4231
|
+
if (value === "true")
|
|
4232
|
+
return true;
|
|
4233
|
+
if (value === "false")
|
|
4234
|
+
return false;
|
|
4235
|
+
if (value === "null")
|
|
4236
|
+
return null;
|
|
4237
|
+
if (value !== "" && !isNaN(Number(value)))
|
|
4238
|
+
return Number(value);
|
|
4239
|
+
return value;
|
|
4240
|
+
}
|
|
4181
4241
|
/**
|
|
4182
4242
|
* Get instance from element
|
|
4183
4243
|
* @param {Element} element - DOM element
|
|
@@ -4278,6 +4338,32 @@ ${blockSuffix}` : suffix;
|
|
|
4278
4338
|
}
|
|
4279
4339
|
});
|
|
4280
4340
|
}
|
|
4341
|
+
/**
|
|
4342
|
+
* Set custom syntax processor for extending markdown parsing
|
|
4343
|
+
* @param {Function|null} processor - Function that takes (html) and returns modified HTML
|
|
4344
|
+
* @example
|
|
4345
|
+
* OverType.setCustomSyntax((html) => {
|
|
4346
|
+
* // Highlight footnote references [^1]
|
|
4347
|
+
* return html.replace(/\[\^(\w+)\]/g, '<span class="footnote-ref">$&</span>');
|
|
4348
|
+
* });
|
|
4349
|
+
*/
|
|
4350
|
+
static setCustomSyntax(processor) {
|
|
4351
|
+
MarkdownParser.setCustomSyntax(processor);
|
|
4352
|
+
document.querySelectorAll(".overtype-wrapper").forEach((wrapper) => {
|
|
4353
|
+
const instance = wrapper._instance;
|
|
4354
|
+
if (instance && instance.updatePreview) {
|
|
4355
|
+
instance.updatePreview();
|
|
4356
|
+
}
|
|
4357
|
+
});
|
|
4358
|
+
document.querySelectorAll("overtype-editor").forEach((webComponent) => {
|
|
4359
|
+
if (typeof webComponent.getEditor === "function") {
|
|
4360
|
+
const instance = webComponent.getEditor();
|
|
4361
|
+
if (instance && instance.updatePreview) {
|
|
4362
|
+
instance.updatePreview();
|
|
4363
|
+
}
|
|
4364
|
+
}
|
|
4365
|
+
});
|
|
4366
|
+
}
|
|
4281
4367
|
/**
|
|
4282
4368
|
* Initialize global event listeners
|
|
4283
4369
|
*/
|
|
@@ -4348,9 +4434,10 @@ ${blockSuffix}` : suffix;
|
|
|
4348
4434
|
*/
|
|
4349
4435
|
|
|
4350
4436
|
if (typeof window !== "undefined" && typeof window.document !== "undefined") {
|
|
4351
|
-
|
|
4437
|
+
// Extract exports BEFORE reassigning OverType (var OverType is window.OverType)
|
|
4352
4438
|
window.toolbarButtons = OverType.toolbarButtons;
|
|
4353
4439
|
window.defaultToolbarButtons = OverType.defaultToolbarButtons;
|
|
4440
|
+
window.OverType = OverType.default ? OverType.default : OverType;
|
|
4354
4441
|
}
|
|
4355
4442
|
|
|
4356
4443
|
//# sourceMappingURL=overtype.js.map
|