Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preserveBlank config param #105

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ All properties are optional.
| placeholder | `string` | header's placeholder string |
| levels | `number[]` | enabled heading levels |
| defaultLevel | `number` | default heading level |
| preserveBlank | `boolean` | (default: `false`) Whether or not to keep blank headers when saving editor data |

```javascript
var editor = EditorJS({
Expand Down
18 changes: 17 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { IconH1, IconH2, IconH3, IconH4, IconH5, IconH6, IconHeading } from '@co
* @property {string} placeholder — Block's placeholder
* @property {number[]} levels — Heading levels
* @property {number} defaultLevel — default level
* @property {boolean} preserveBlank - Whether or not to keep blank headers when saving editor data
*/

/**
Expand Down Expand Up @@ -160,7 +161,11 @@ export default class Header {
* @public
*/
validate(blockData) {
return blockData.text.trim() !== '';
if (blockData.text.trim() === '' && !this.preserveBlank) {
return false;
}

return true;
}

/**
Expand Down Expand Up @@ -399,6 +404,17 @@ export default class Header {
) : availableLevels;
}

/**
* Get preserveBlank
*
* @returns {preserveBlank}
*/
get preserveBlank() {
let preserveBlank = this._settings.preserveBlank || false;

return preserveBlank;
}

/**
* Handle H1-H6 tags on paste to substitute it with header Tool
*
Expand Down