overtype 1.2.0 → 1.2.2
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 +23 -3
- package/dist/overtype.cjs +851 -977
- package/dist/overtype.cjs.map +4 -4
- package/dist/overtype.esm.js +53 -30
- package/dist/overtype.esm.js.map +2 -2
- package/dist/overtype.js +53 -30
- package/dist/overtype.js.map +2 -2
- package/dist/overtype.min.js +45 -39
- package/package.json +5 -2
- package/src/overtype.js +33 -28
- package/src/parser.js +48 -19
- package/src/styles.js +6 -0
package/dist/overtype.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* OverType v1.2.
|
|
2
|
+
* OverType v1.2.2
|
|
3
3
|
* A lightweight markdown editor library with perfect WYSIWYG alignment
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @author Demo User
|
|
@@ -234,11 +234,22 @@ var MarkdownParser = class {
|
|
|
234
234
|
static parse(text, activeLine = -1, showActiveLineRaw = false) {
|
|
235
235
|
this.resetLinkIndex();
|
|
236
236
|
const lines = text.split("\n");
|
|
237
|
+
let inCodeBlock = false;
|
|
237
238
|
const parsedLines = lines.map((line, index) => {
|
|
238
239
|
if (showActiveLineRaw && index === activeLine) {
|
|
239
240
|
const content = this.escapeHtml(line) || " ";
|
|
240
241
|
return `<div class="raw-line">${content}</div>`;
|
|
241
242
|
}
|
|
243
|
+
const codeFenceRegex = /^```[^`]*$/;
|
|
244
|
+
if (codeFenceRegex.test(line)) {
|
|
245
|
+
inCodeBlock = !inCodeBlock;
|
|
246
|
+
return this.parseLine(line);
|
|
247
|
+
}
|
|
248
|
+
if (inCodeBlock) {
|
|
249
|
+
const escaped = this.escapeHtml(line);
|
|
250
|
+
const indented = this.preserveIndentation(escaped, line);
|
|
251
|
+
return `<div>${indented || " "}</div>`;
|
|
252
|
+
}
|
|
242
253
|
return this.parseLine(line);
|
|
243
254
|
});
|
|
244
255
|
const html = parsedLines.join("");
|
|
@@ -278,23 +289,22 @@ var MarkdownParser = class {
|
|
|
278
289
|
if (lang) {
|
|
279
290
|
codeElement.className = `language-${lang}`;
|
|
280
291
|
}
|
|
281
|
-
container.insertBefore(currentCodeBlock, child);
|
|
282
|
-
|
|
292
|
+
container.insertBefore(currentCodeBlock, child.nextSibling);
|
|
293
|
+
currentCodeBlock._codeElement = codeElement;
|
|
283
294
|
continue;
|
|
284
295
|
} else {
|
|
285
296
|
inCodeBlock = false;
|
|
286
297
|
currentCodeBlock = null;
|
|
287
|
-
child.remove();
|
|
288
298
|
continue;
|
|
289
299
|
}
|
|
290
300
|
}
|
|
291
301
|
}
|
|
292
302
|
if (inCodeBlock && currentCodeBlock && child.tagName === "DIV" && !child.querySelector(".code-fence")) {
|
|
293
|
-
const codeElement = currentCodeBlock.querySelector("code");
|
|
303
|
+
const codeElement = currentCodeBlock._codeElement || currentCodeBlock.querySelector("code");
|
|
294
304
|
if (codeElement.textContent.length > 0) {
|
|
295
305
|
codeElement.textContent += "\n";
|
|
296
306
|
}
|
|
297
|
-
const lineText = child.
|
|
307
|
+
const lineText = child.textContent.replace(/\u00A0/g, " ");
|
|
298
308
|
codeElement.textContent += lineText;
|
|
299
309
|
child.remove();
|
|
300
310
|
continue;
|
|
@@ -347,15 +357,19 @@ var MarkdownParser = class {
|
|
|
347
357
|
}
|
|
348
358
|
return match;
|
|
349
359
|
});
|
|
350
|
-
const codeBlockRegex = /<div><span class="code-fence"
|
|
351
|
-
processed = processed.replace(codeBlockRegex, (match,
|
|
360
|
+
const codeBlockRegex = /<div><span class="code-fence">(```[^<]*)<\/span><\/div>(.*?)<div><span class="code-fence">(```)<\/span><\/div>/gs;
|
|
361
|
+
processed = processed.replace(codeBlockRegex, (match, openFence, content, closeFence) => {
|
|
352
362
|
const lines = content.match(/<div>(.*?)<\/div>/gs) || [];
|
|
353
363
|
const codeContent = lines.map((line) => {
|
|
354
|
-
const text = line.replace(/<div>(.*?)<\/div>/s, "$1").replace(/ /g, " ")
|
|
364
|
+
const text = line.replace(/<div>(.*?)<\/div>/s, "$1").replace(/ /g, " ");
|
|
355
365
|
return text;
|
|
356
366
|
}).join("\n");
|
|
357
|
-
const
|
|
358
|
-
|
|
367
|
+
const lang = openFence.slice(3).trim();
|
|
368
|
+
const langClass = lang ? ` class="language-${lang}"` : "";
|
|
369
|
+
let result = `<div><span class="code-fence">${openFence}</span></div>`;
|
|
370
|
+
result += `<pre class="code-block"><code${langClass}>${codeContent}</code></pre>`;
|
|
371
|
+
result += `<div><span class="code-fence">${closeFence}</span></div>`;
|
|
372
|
+
return result;
|
|
359
373
|
});
|
|
360
374
|
return processed;
|
|
361
375
|
}
|
|
@@ -1496,11 +1510,17 @@ function generateStyles(options = {}) {
|
|
|
1496
1510
|
position: relative !important; /* Override reset - needed for absolute children */
|
|
1497
1511
|
overflow: visible !important; /* Allow dropdown to overflow container */
|
|
1498
1512
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
|
|
1513
|
+
text-align: left !important;
|
|
1499
1514
|
${themeVars ? `
|
|
1500
1515
|
/* Theme Variables */
|
|
1501
1516
|
${themeVars}` : ""}
|
|
1502
1517
|
}
|
|
1503
1518
|
|
|
1519
|
+
/* Force left alignment for all elements in the editor */
|
|
1520
|
+
.overtype-container .overtype-wrapper * {
|
|
1521
|
+
text-align: left !important;
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1504
1524
|
/* Auto-resize mode styles */
|
|
1505
1525
|
.overtype-container.overtype-auto-resize {
|
|
1506
1526
|
height: auto !important;
|
|
@@ -3055,17 +3075,6 @@ var _OverType = class _OverType {
|
|
|
3055
3075
|
closeFence.style.display = "block";
|
|
3056
3076
|
openParent.classList.add("code-block-line");
|
|
3057
3077
|
closeParent.classList.add("code-block-line");
|
|
3058
|
-
let currentDiv = openParent.nextElementSibling;
|
|
3059
|
-
while (currentDiv && currentDiv !== closeParent) {
|
|
3060
|
-
if (currentDiv.tagName === "DIV") {
|
|
3061
|
-
currentDiv.classList.add("code-block-line");
|
|
3062
|
-
const plainText = currentDiv.textContent;
|
|
3063
|
-
currentDiv.textContent = plainText;
|
|
3064
|
-
}
|
|
3065
|
-
currentDiv = currentDiv.nextElementSibling;
|
|
3066
|
-
if (!currentDiv)
|
|
3067
|
-
break;
|
|
3068
|
-
}
|
|
3069
3078
|
}
|
|
3070
3079
|
}
|
|
3071
3080
|
/**
|
|
@@ -3099,21 +3108,35 @@ var _OverType = class _OverType {
|
|
|
3099
3108
|
const after = value.substring(end);
|
|
3100
3109
|
const lines = selection.split("\n");
|
|
3101
3110
|
const outdented = lines.map((line) => line.replace(/^ /, "")).join("\n");
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3111
|
+
if (document.execCommand) {
|
|
3112
|
+
this.textarea.setSelectionRange(start, end);
|
|
3113
|
+
document.execCommand("insertText", false, outdented);
|
|
3114
|
+
} else {
|
|
3115
|
+
this.textarea.value = before + outdented + after;
|
|
3116
|
+
this.textarea.selectionStart = start;
|
|
3117
|
+
this.textarea.selectionEnd = start + outdented.length;
|
|
3118
|
+
}
|
|
3105
3119
|
} else if (start !== end) {
|
|
3106
3120
|
const before = value.substring(0, start);
|
|
3107
3121
|
const selection = value.substring(start, end);
|
|
3108
3122
|
const after = value.substring(end);
|
|
3109
3123
|
const lines = selection.split("\n");
|
|
3110
3124
|
const indented = lines.map((line) => " " + line).join("\n");
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3125
|
+
if (document.execCommand) {
|
|
3126
|
+
this.textarea.setSelectionRange(start, end);
|
|
3127
|
+
document.execCommand("insertText", false, indented);
|
|
3128
|
+
} else {
|
|
3129
|
+
this.textarea.value = before + indented + after;
|
|
3130
|
+
this.textarea.selectionStart = start;
|
|
3131
|
+
this.textarea.selectionEnd = start + indented.length;
|
|
3132
|
+
}
|
|
3114
3133
|
} else {
|
|
3115
|
-
|
|
3116
|
-
|
|
3134
|
+
if (document.execCommand) {
|
|
3135
|
+
document.execCommand("insertText", false, " ");
|
|
3136
|
+
} else {
|
|
3137
|
+
this.textarea.value = value.substring(0, start) + " " + value.substring(end);
|
|
3138
|
+
this.textarea.selectionStart = this.textarea.selectionEnd = start + 2;
|
|
3139
|
+
}
|
|
3117
3140
|
}
|
|
3118
3141
|
this.textarea.dispatchEvent(new Event("input", { bubbles: true }));
|
|
3119
3142
|
return;
|