From f17122e870120f8025d29e78988eb725553f9720 Mon Sep 17 00:00:00 2001 From: Matt Spence Date: Fri, 17 Dec 2021 23:07:31 +0000 Subject: [PATCH 1/2] Feat: new config setting `allowLineBreaks: Boolean` Allow a Header Tool's text to include break line `
` tags when a user presses Shift + Enter. By default, this is disabled, the developer can choose to enable through the tool's config: ``` config: { allowLineBreaks: true, } ``` Fixes https://github.com/editor-js/header/issues/73 --- src/index.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 8230e7c..4b79498 100644 --- a/src/index.js +++ b/src/index.js @@ -227,10 +227,14 @@ class Header { * @public */ save(toolsContent) { - return { - text: toolsContent.innerHTML, + const sanitizerConfig = { + br: !(typeof this._settings.allowLineBreaks === 'undefined' || this._settings.allowLineBreaks === false), + } + + return Object.assign({}, { + text: this.api.sanitizer.clean(toolsContent.innerHTML, sanitizerConfig), level: this.currentLevel.number, - }; + }); } /** @@ -249,7 +253,9 @@ class Header { static get sanitize() { return { level: false, - text: {}, + text: { + br: true, + }, }; } From 10fdaf81300c65b5cb0921694ca0ab35db5054c9 Mon Sep 17 00:00:00 2001 From: Matt Spence Date: Fri, 17 Dec 2021 23:35:35 +0000 Subject: [PATCH 2/2] Mod: update docs to include ` allowLineBreaks` config option --- README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index aaf9216..8320569 100644 --- a/README.md +++ b/README.md @@ -78,11 +78,12 @@ var editor = EditorJS({ All properties are optional. -| Field | Type | Description | -| ------------ | ---------- | --------------------------- | -| placeholder | `string` | header's placeholder string | -| levels | `number[]` | enabled heading levels | -| defaultLevel | `number` | default heading level | +| Field | Type | Description | +| --------------- | ---------- | ----------------------------------- | +| placeholder | `string` | header's placeholder string | +| levels | `number[]` | enabled heading levels | +| defaultLevel | `number` | default heading level | +| allowLineBreaks | `bool` | allow line breaks. default: `false` | ```javascript var editor = EditorJS({ @@ -95,7 +96,8 @@ var editor = EditorJS({ config: { placeholder: 'Enter a header', levels: [2, 3, 4], - defaultLevel: 3 + defaultLevel: 3, + allowLineBreaks: true } } }