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/dist/overtype.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * OverType v1.2.0
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
@@ -258,11 +258,22 @@ var OverType = (() => {
258
258
  static parse(text, activeLine = -1, showActiveLineRaw = false) {
259
259
  this.resetLinkIndex();
260
260
  const lines = text.split("\n");
261
+ let inCodeBlock = false;
261
262
  const parsedLines = lines.map((line, index) => {
262
263
  if (showActiveLineRaw && index === activeLine) {
263
264
  const content = this.escapeHtml(line) || " ";
264
265
  return `<div class="raw-line">${content}</div>`;
265
266
  }
267
+ const codeFenceRegex = /^```[^`]*$/;
268
+ if (codeFenceRegex.test(line)) {
269
+ inCodeBlock = !inCodeBlock;
270
+ return this.parseLine(line);
271
+ }
272
+ if (inCodeBlock) {
273
+ const escaped = this.escapeHtml(line);
274
+ const indented = this.preserveIndentation(escaped, line);
275
+ return `<div>${indented || "&nbsp;"}</div>`;
276
+ }
266
277
  return this.parseLine(line);
267
278
  });
268
279
  const html = parsedLines.join("");
@@ -302,23 +313,22 @@ var OverType = (() => {
302
313
  if (lang) {
303
314
  codeElement.className = `language-${lang}`;
304
315
  }
305
- container.insertBefore(currentCodeBlock, child);
306
- child.remove();
316
+ container.insertBefore(currentCodeBlock, child.nextSibling);
317
+ currentCodeBlock._codeElement = codeElement;
307
318
  continue;
308
319
  } else {
309
320
  inCodeBlock = false;
310
321
  currentCodeBlock = null;
311
- child.remove();
312
322
  continue;
313
323
  }
314
324
  }
315
325
  }
316
326
  if (inCodeBlock && currentCodeBlock && child.tagName === "DIV" && !child.querySelector(".code-fence")) {
317
- const codeElement = currentCodeBlock.querySelector("code");
327
+ const codeElement = currentCodeBlock._codeElement || currentCodeBlock.querySelector("code");
318
328
  if (codeElement.textContent.length > 0) {
319
329
  codeElement.textContent += "\n";
320
330
  }
321
- const lineText = child.innerHTML.replace(/&nbsp;/g, " ").replace(/<[^>]*>/g, "");
331
+ const lineText = child.textContent.replace(/\u00A0/g, " ");
322
332
  codeElement.textContent += lineText;
323
333
  child.remove();
324
334
  continue;
@@ -371,15 +381,19 @@ var OverType = (() => {
371
381
  }
372
382
  return match;
373
383
  });
374
- const codeBlockRegex = /<div><span class="code-fence">```([^<]*)<\/span><\/div>(.*?)<div><span class="code-fence">```<\/span><\/div>/gs;
375
- processed = processed.replace(codeBlockRegex, (match, lang, content) => {
384
+ const codeBlockRegex = /<div><span class="code-fence">(```[^<]*)<\/span><\/div>(.*?)<div><span class="code-fence">(```)<\/span><\/div>/gs;
385
+ processed = processed.replace(codeBlockRegex, (match, openFence, content, closeFence) => {
376
386
  const lines = content.match(/<div>(.*?)<\/div>/gs) || [];
377
387
  const codeContent = lines.map((line) => {
378
- const text = line.replace(/<div>(.*?)<\/div>/s, "$1").replace(/&nbsp;/g, " ").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&amp;/g, "&");
388
+ const text = line.replace(/<div>(.*?)<\/div>/s, "$1").replace(/&nbsp;/g, " ");
379
389
  return text;
380
390
  }).join("\n");
381
- const langClass = lang ? ` class="language-${lang.trim()}"` : "";
382
- return `<pre class="code-block"><code${langClass}>${this.escapeHtml(codeContent)}</code></pre>`;
391
+ const lang = openFence.slice(3).trim();
392
+ const langClass = lang ? ` class="language-${lang}"` : "";
393
+ let result = `<div><span class="code-fence">${openFence}</span></div>`;
394
+ result += `<pre class="code-block"><code${langClass}>${codeContent}</code></pre>`;
395
+ result += `<div><span class="code-fence">${closeFence}</span></div>`;
396
+ return result;
383
397
  });
384
398
  return processed;
385
399
  }
@@ -1520,11 +1534,17 @@ ${blockSuffix}` : suffix;
1520
1534
  position: relative !important; /* Override reset - needed for absolute children */
1521
1535
  overflow: visible !important; /* Allow dropdown to overflow container */
1522
1536
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
1537
+ text-align: left !important;
1523
1538
  ${themeVars ? `
1524
1539
  /* Theme Variables */
1525
1540
  ${themeVars}` : ""}
1526
1541
  }
1527
1542
 
1543
+ /* Force left alignment for all elements in the editor */
1544
+ .overtype-container .overtype-wrapper * {
1545
+ text-align: left !important;
1546
+ }
1547
+
1528
1548
  /* Auto-resize mode styles */
1529
1549
  .overtype-container.overtype-auto-resize {
1530
1550
  height: auto !important;
@@ -3079,17 +3099,6 @@ ${blockSuffix}` : suffix;
3079
3099
  closeFence.style.display = "block";
3080
3100
  openParent.classList.add("code-block-line");
3081
3101
  closeParent.classList.add("code-block-line");
3082
- let currentDiv = openParent.nextElementSibling;
3083
- while (currentDiv && currentDiv !== closeParent) {
3084
- if (currentDiv.tagName === "DIV") {
3085
- currentDiv.classList.add("code-block-line");
3086
- const plainText = currentDiv.textContent;
3087
- currentDiv.textContent = plainText;
3088
- }
3089
- currentDiv = currentDiv.nextElementSibling;
3090
- if (!currentDiv)
3091
- break;
3092
- }
3093
3102
  }
3094
3103
  }
3095
3104
  /**
@@ -3123,21 +3132,35 @@ ${blockSuffix}` : suffix;
3123
3132
  const after = value.substring(end);
3124
3133
  const lines = selection.split("\n");
3125
3134
  const outdented = lines.map((line) => line.replace(/^ /, "")).join("\n");
3126
- this.textarea.value = before + outdented + after;
3127
- this.textarea.selectionStart = start;
3128
- this.textarea.selectionEnd = start + outdented.length;
3135
+ if (document.execCommand) {
3136
+ this.textarea.setSelectionRange(start, end);
3137
+ document.execCommand("insertText", false, outdented);
3138
+ } else {
3139
+ this.textarea.value = before + outdented + after;
3140
+ this.textarea.selectionStart = start;
3141
+ this.textarea.selectionEnd = start + outdented.length;
3142
+ }
3129
3143
  } else if (start !== end) {
3130
3144
  const before = value.substring(0, start);
3131
3145
  const selection = value.substring(start, end);
3132
3146
  const after = value.substring(end);
3133
3147
  const lines = selection.split("\n");
3134
3148
  const indented = lines.map((line) => " " + line).join("\n");
3135
- this.textarea.value = before + indented + after;
3136
- this.textarea.selectionStart = start;
3137
- this.textarea.selectionEnd = start + indented.length;
3149
+ if (document.execCommand) {
3150
+ this.textarea.setSelectionRange(start, end);
3151
+ document.execCommand("insertText", false, indented);
3152
+ } else {
3153
+ this.textarea.value = before + indented + after;
3154
+ this.textarea.selectionStart = start;
3155
+ this.textarea.selectionEnd = start + indented.length;
3156
+ }
3138
3157
  } else {
3139
- this.textarea.value = value.substring(0, start) + " " + value.substring(end);
3140
- this.textarea.selectionStart = this.textarea.selectionEnd = start + 2;
3158
+ if (document.execCommand) {
3159
+ document.execCommand("insertText", false, " ");
3160
+ } else {
3161
+ this.textarea.value = value.substring(0, start) + " " + value.substring(end);
3162
+ this.textarea.selectionStart = this.textarea.selectionEnd = start + 2;
3163
+ }
3141
3164
  }
3142
3165
  this.textarea.dispatchEvent(new Event("input", { bubbles: true }));
3143
3166
  return;