Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
propIsFunction(this.props.children);
// Check whether the editable prop has been updated
if (this.props.editable !== editable && this.view && this.editorRef) {
this.view.setProps({ ...this.view.props, editable: () => this.props.editable });
}
// Check if the manager has changed
if (!prevManager.isEqual(this.props.manager)) {
this.updateExtensionManager();
this.view.setProps({ ...this.view.props, nodeViews: this.manager.data.nodeViews });
// The following converts the current content to HTML and then uses the
// new manager schema to convert it back into a ProsemirrorNode for
// compatibility with the new manager.
const htmlString = toHTML({ node: this.state.editor.newState.doc, schema: prevManager.schema });
const newContent = fromHTML({ schema: this.manager.schema, content: htmlString, doc: this.doc });
this.setContent(newContent, true);
}
const { newState } = this.state.editor;
// Check if this is controlled component and run the post update handler
if (this.props.onStateChange && newState !== prevState.editor.newState) {
// The update was caused by an internal change
this.controlledUpdate(newState);
}
}
it('creates the correct dom node', () => {
expect(toHTML({ node: codeBlock(content), schema })).toBe(
`<pre class="language-${attrs.language}"><code data-code-block-language="${attrs.language}">${content}</code></pre>`,
);
});
it('creates the correct dom node', () => {
expect(toHTML({ node: p(mention(attrs.label)), schema })).toMatchInlineSnapshot(`
<p>
<a data-mention-name="testing" data-mention-id="test" class="mention mention-testing">
@test
</a>
</p>
`);
});
test('does not support nested paragraph tags', () => {
const node = mentionAt.create(
{ id: 'test', label: '@label' },
paragraph.create({}, schema.text('Content here')),
);
expect(toHTML({ node, schema })).toBe('<a data-mention-at-id="test" class="mention mention-at">@label</a>');
});
it('it produces valid html', () => {
({ schema } = createBaseTestManager([{ extension: new ParagraphExtension(), priority: 1 }]));
({ doc, p } = pmBuild(schema, {
p: { nodeType: 'paragraph', indent: 1, align: 'right', lineSpacing: '100%', id: 'never' },
}));
const html = toHTML({
node: p('hello'),
schema,
});
expect(html).toBe(`<p id="never" data-indent="1" style="text-align: right;line-height: 100%;">hello</p>`);
});
});
test('can be configured with attribute node extensions', () => {
const expected = 'A heading';
const {
view: { dom },
schema,
nodes: { doc },
attrNodes: { heading },
add,
} = renderEditor({ attrNodes: [new HeadingExtension()] });
const h3 = heading({ level: 3 });
const h2 = heading({ level: 2 });
add(doc(h2(expected), h3(expected)));
expect(dom).toContainHTML(toHTML({ node: h3(expected), schema }));
expect(dom).toContainHTML(toHTML({ node: h2(expected), schema }));
});
it('uses the href', () => {
expect(toHTML({ node: p(a('link')), schema })).toBe(
`<p><a rel="noopener noreferrer nofollow" href="${href}">link</a></p>`,
);
});
it('can replace text with nodes', () => {
const node = p('Brilliant');
const nodeTwo = p('Wonderful');
const expected = toHTML({ node, schema });
const expectedTwo = toHTML({ node: nodeTwo, schema });
add(doc(p('Today is a sad day'))).replace(node, nodeTwo);
expect(dom).toContainHTML(expected);
expect(dom).toContainHTML(expectedTwo);
});
});
it('overwrites the whole doc on each call', () => {
const node = p('Hello');
const nodeTwo = p('Tolu');
const expected = toHTML({ node, schema });
const expectedTwo = toHTML({ node: nodeTwo, schema });
add(doc(node));
expect(dom).toContainHTML(expected);
add(doc(nodeTwo));
expect(dom).toContainHTML(expectedTwo);
expect(dom).not.toContainHTML(expected);
});
it('defaults to level 1', () => {
expect(toHTML({ node: h1('Heading'), schema })).toBe('<h1>Heading</h1>');
});