How to use the @remirror/core.toHTML function in @remirror/core

To help you get started, we’ve selected a few @remirror/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ifiokjr / remirror / @remirror / react / src / components / remirror.tsx View on Github external
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);
    }
  }
github ifiokjr / remirror / @remirror / extension-code-block / src / __tests__ / code-block.spec.ts View on Github external
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>`,
    );
  });
github ifiokjr / remirror / @remirror / extension-mention / src / __tests__ / mention.spec.ts View on Github external
it('creates the correct dom node', () =&gt; {
    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>
    `);
  });
github ifiokjr / remirror / @remirror / extension-mention / src / __tests__ / mention-schema.spec.ts View on Github external
test('does not support nested paragraph tags', () =&gt; {
  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>');
});
github ifiokjr / remirror / @remirror / core-extensions / src / nodes / paragraph / __tests__ / paragraph-extension.spec.ts View on Github external
it('it produces valid html', () =&gt; {
    ({ 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>`);
  });
});
github ifiokjr / remirror / packages / jest-remirror / src / __tests__ / jest-remirror-editor.spec.ts View on Github external
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 }));
});
github ifiokjr / remirror / @remirror / core-extensions / src / marks / __tests__ / link-extension.spec.ts View on Github external
it('uses the href', () =&gt; {
    expect(toHTML({ node: p(a('link')), schema })).toBe(
      `<p><a rel="noopener noreferrer nofollow" href="${href}">link</a></p>`,
    );
  });
github ifiokjr / remirror / packages / jest-remirror / src / __tests__ / jest-remirror-editor.spec.ts View on Github external
it('can replace text with nodes', () =&gt; {
    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);
  });
});
github ifiokjr / remirror / packages / jest-remirror / src / __tests__ / jest-remirror-editor.spec.ts View on Github external
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);
  });
github ifiokjr / remirror / @remirror / core-extensions / src / nodes / __tests__ / heading-extension.spec.ts View on Github external
it('defaults to level 1', () =&gt; {
    expect(toHTML({ node: h1('Heading'), schema })).toBe('<h1>Heading</h1>');
  });