Skip to content

Commit

Permalink
fix: validate against input HTML
Browse files Browse the repository at this point in the history
  • Loading branch information
sibiraj-s committed Dec 30, 2020
1 parent eae7157 commit 9b25119
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/lib/validators.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AbstractControl, ValidatorFn } from '@angular/forms';
import { Schema } from 'prosemirror-model';

import { toDoc } from './html';
import schema from './schema';

// @dynamic
Expand All @@ -11,11 +12,19 @@ export class Validators {

const userSchema = customSchema || schema;

if (!c.value) {
const value = c.value;
if (!value) {
return null;
}

const node = userSchema.nodeFromJSON(c.value);
let doc = null;
if (typeof value === 'string') {
doc = toDoc(value, userSchema);
} else {
doc = value;
}

const node = userSchema.nodeFromJSON(doc);

const isEmpty = node.childCount === 1
&& node?.firstChild?.isTextblock
Expand Down

0 comments on commit 9b25119

Please sign in to comment.