cm-md-editor 2.3.1 → 2.3.3
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/package.json +1 -1
- package/src/MdEditor.js +16 -4
package/package.json
CHANGED
package/src/MdEditor.js
CHANGED
|
@@ -27,6 +27,10 @@ export class MdEditor {
|
|
|
27
27
|
this.element.addEventListener('keydown', (e) => this.handleKeyDown(e))
|
|
28
28
|
this.createToolbar()
|
|
29
29
|
this.createHighlightBackdrop()
|
|
30
|
+
if (!this.wrapEnabled && this.highlightLayer) {
|
|
31
|
+
this.highlightLayer.style.whiteSpace = 'pre'
|
|
32
|
+
this.highlightLayer.style.overflowWrap = 'normal'
|
|
33
|
+
}
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
createToolbar() {
|
|
@@ -73,7 +77,9 @@ export class MdEditor {
|
|
|
73
77
|
toolbar.appendChild(spacer)
|
|
74
78
|
|
|
75
79
|
// Wrap toggle button
|
|
76
|
-
this.
|
|
80
|
+
this.wrapStorageKey = 'mdEditor_wrap_' + (this.element.id || this.element.name || 'default')
|
|
81
|
+
const savedWrap = localStorage.getItem(this.wrapStorageKey)
|
|
82
|
+
this.wrapEnabled = savedWrap !== null ? savedWrap === 'true' : true
|
|
77
83
|
this.wrapButton = document.createElement('button')
|
|
78
84
|
this.wrapButton.type = 'button'
|
|
79
85
|
this.wrapButton.title = 'Toggle word wrap'
|
|
@@ -86,8 +92,13 @@ export class MdEditor {
|
|
|
86
92
|
e.preventDefault()
|
|
87
93
|
this.toggleWrapMode()
|
|
88
94
|
})
|
|
89
|
-
this.wrapButton.style.opacity = '0.9'
|
|
95
|
+
this.wrapButton.style.opacity = this.wrapEnabled ? '0.9' : '0.4'
|
|
90
96
|
toolbar.appendChild(this.wrapButton)
|
|
97
|
+
// Apply saved wrap state
|
|
98
|
+
if (!this.wrapEnabled) {
|
|
99
|
+
this.element.style.whiteSpace = 'pre'
|
|
100
|
+
this.element.style.overflowX = 'auto'
|
|
101
|
+
}
|
|
91
102
|
}
|
|
92
103
|
|
|
93
104
|
createHighlightBackdrop() {
|
|
@@ -290,7 +301,7 @@ export class MdEditor {
|
|
|
290
301
|
'<span style="color:rgba(' + c('colorEscape') + ',1)">\\</span>$1')
|
|
291
302
|
|
|
292
303
|
// Unordered list markers with optional task list checkbox
|
|
293
|
-
result = result.replace(/^(
|
|
304
|
+
result = result.replace(/^((?:\t| )*)(- )(\[[ xX]\] )?/, (_, tabs, marker, task) => {
|
|
294
305
|
let r = tabs + this.colorSpan('colorList', marker)
|
|
295
306
|
if (task) {
|
|
296
307
|
r += this.colorSpan('colorList', task)
|
|
@@ -299,7 +310,7 @@ export class MdEditor {
|
|
|
299
310
|
})
|
|
300
311
|
|
|
301
312
|
// Ordered list markers
|
|
302
|
-
result = result.replace(/^(
|
|
313
|
+
result = result.replace(/^((?:\t| )*)(\d+\. )/, (_, tabs, marker) =>
|
|
303
314
|
tabs + this.colorSpan('colorList', marker))
|
|
304
315
|
|
|
305
316
|
// Images  and Links [text](url)
|
|
@@ -333,6 +344,7 @@ export class MdEditor {
|
|
|
333
344
|
|
|
334
345
|
toggleWrapMode() {
|
|
335
346
|
this.wrapEnabled = !this.wrapEnabled
|
|
347
|
+
localStorage.setItem(this.wrapStorageKey, this.wrapEnabled)
|
|
336
348
|
const wrap = this.wrapEnabled
|
|
337
349
|
this.element.style.whiteSpace = wrap ? 'pre-wrap' : 'pre'
|
|
338
350
|
this.element.style.overflowX = wrap ? 'hidden' : 'auto'
|