cm-md-editor 2.2.1 → 2.3.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/index.html CHANGED
@@ -17,6 +17,7 @@
17
17
  font-family: monospace;
18
18
  tab-size: 4;
19
19
  line-height: 1.3;
20
+ background-color: #111;
20
21
  }
21
22
  </style>
22
23
  </head>
@@ -35,7 +36,7 @@ description: Some example text for the editor
35
36
 
36
37
  ### Heading 3
37
38
 
38
- This is a minimal **markdown editor** with _italic_ and **_bold italic_** text. You can also use ~~strikethrough~~ for deleted text.
39
+ This is a minimal **markdown editor** with _italic_ and *also italic* and **_bold italic_** text. You can also use ~~strikethrough~~ for deleted text.
39
40
 
40
41
  <!-- This is a comment -->
41
42
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-md-editor",
3
- "version": "2.2.1",
3
+ "version": "2.3.1",
4
4
  "description": "a simple markdown editor",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/MdEditor.js CHANGED
@@ -102,7 +102,7 @@ export class MdEditor {
102
102
  // Copy textarea computed styles to backdrop
103
103
  const cs = window.getComputedStyle(this.element)
104
104
  this.backdrop.style.cssText = `position:absolute;overflow:hidden;pointer-events:none;z-index:1;opacity:${this.props.syntaxHighlight};`
105
- this.highlightLayer.style.cssText = `white-space:pre-wrap;word-wrap:break-word;overflow-wrap:break-word;color:transparent;`
105
+ this.highlightLayer.style.cssText = `white-space:pre-wrap;word-wrap:break-word;overflow-wrap:break-word;`
106
106
 
107
107
  const syncStyles = () => {
108
108
  const cs = window.getComputedStyle(this.element)
@@ -121,17 +121,23 @@ export class MdEditor {
121
121
  }
122
122
  syncStyles()
123
123
 
124
- // Make textarea background transparent so backdrop shows through
124
+ // Move textarea bg to backdrop, make textarea transparent so backdrop shows through
125
+ const originalBg = cs.getPropertyValue('background-color')
126
+ this.backdrop.style.background = originalBg
125
127
  this.element.style.overscrollBehavior = 'none'
126
128
  this.element.style.background = 'transparent'
127
129
  this.element.style.position = 'relative'
128
- this.element.style.caretColor = cs.color
129
-
130
- // Sync scroll
131
- this.element.addEventListener('scroll', () => {
132
- this.backdrop.scrollTop = this.element.scrollTop
133
- this.backdrop.scrollLeft = this.element.scrollLeft
134
- })
130
+ this.element.style.zIndex = '2'
131
+ const originalColor = cs.color
132
+ this.element.style.caretColor = originalColor
133
+ this.element.style.color = 'transparent'
134
+ this.highlightLayer.style.color = originalColor
135
+
136
+ // Sync scroll via transform — no visible jitter since all text is in the highlight layer
137
+ const syncScroll = () => {
138
+ this.highlightLayer.style.transform = `translate(${-this.element.scrollLeft}px, ${-this.element.scrollTop}px)`
139
+ }
140
+ this.element.addEventListener('scroll', syncScroll)
135
141
 
136
142
  // Update on input
137
143
  this.element.addEventListener('input', () => this.updateHighlight())
@@ -312,8 +318,10 @@ export class MdEditor {
312
318
  result = result.replace(/(\*\*)(.*?)(\*\*)/g, (_, p1, p2, p3) =>
313
319
  this.colorSpan('colorBold', p1) + this.colorSpan('colorBold', p2) + this.colorSpan('colorBold', p3))
314
320
 
315
- // Italic _text_
316
- result = result.replace(/((?:^|[^\\]))(\_)(.*?[^\\])(\_)/g, (_, pre, p1, p2, p3) =>
321
+ // Italic _text_ or *text* (single asterisk, after bold has been handled)
322
+ result = result.replace(/((?:^|[^\\*]))(\_)(.*?[^\\])(\_)/g, (_, pre, p1, p2, p3) =>
323
+ pre + this.colorSpan('colorItalic', p1) + this.colorSpan('colorItalic', p2) + this.colorSpan('colorItalic', p3))
324
+ result = result.replace(/((?:^|[^\\*]))(\*)((?!\*).+?[^\\])(\*)/g, (_, pre, p1, p2, p3) =>
317
325
  pre + this.colorSpan('colorItalic', p1) + this.colorSpan('colorItalic', p2) + this.colorSpan('colorItalic', p3))
318
326
 
319
327
  // HTML tags