Skip to content

Commit 2e7b8ed

Browse files
feat: add 'trimLeadingAndTrailingWhitespaces' config
1 parent 1c3c892 commit 2e7b8ed

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default {
1010
editableClass: 'js-editable',
1111
editableDisabledClass: 'js-editable-disabled',
1212
pastingAttribute: 'data-editable-is-pasting',
13+
trimLeadingAndTrailingWhitespaces: true,
1314
boldMarkup: {
1415
type: 'tag',
1516
name: 'strong',

src/content.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as rangeSaveRestore from './range-save-restore'
44
import * as parser from './parser'
55
import * as string from './util/string'
66
import {createElement} from './util/dom'
7+
import config from './config'
78

89
function restoreRange (host, range, func) {
910
range = rangeSaveRestore.save(range)
@@ -161,7 +162,9 @@ function removeWhitespaces (node, type, firstCall = true) {
161162
if (elem?.nodeType !== nodeType.textNode) return
162163
// Remove whitespaces at the end or start of a block with content
163164
// e.g. ' Hello world' > 'Hello World'
164-
elem.textContent = elem.textContent.replace(type.startsWith('last') ? /\s+$/ : /^\s+/, '')
165+
if (config.trimLeadingAndTrailingWhitespaces) {
166+
elem.textContent = elem.textContent.replace(type.startsWith('last') ? / +$/ : /^ +/, '')
167+
}
165168
}
166169

167170
// Remove elements that were inserted for internal or user interface purposes

0 commit comments

Comments
 (0)