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

ParseOptions are not preserved when writing content #78

Open
vlad-kuz opened this issue Dec 12, 2024 · 5 comments
Open

ParseOptions are not preserved when writing content #78

vlad-kuz opened this issue Dec 12, 2024 · 5 comments

Comments

@vlad-kuz
Copy link

create an instance of the editor with parseOptions (https://tiptap.dev/docs/editor/api/editor#parseoptions)

this.tiptapEditor = new Editor({
  ...
  parseOptions: {
    preserveWhitespace: 'full',
  },
  ...

In editor.directive.ts this options are ignored when setting the content and whitespace is collapsed as per HTML's rules.

writeValue(value: Content): void {
  this.editor().chain().setContent(value, false).run();
}
      ...
if (innerHTML) {
  editor.chain().setContent(innerHTML, false).run();
}

To take into account editor configuration, when setting the content, command setContent has third parameter parseOptions.
Code in editor.directive.ts can be changed to.

writeValue(value: Content): void {
  this.editor().chain().setContent(value, false, this.editor().options.parseOptions).run();
}
      ...
if (innerHTML) {
  editor.chain().setContent(innerHTML, false, this.editor.options.parseOptions).run();
}
@sibiraj-s
Copy link
Owner

The parserOptions can be passed during initialization, doesn't need to be set everytime while calling setContent based on the docs https://tiptap.dev/docs/editor/api/commands/content/set-content unless we are looking to override the defaults?

Am I missing something?

@vlad-kuz
Copy link
Author

vlad-kuz commented Dec 12, 2024

Maybe it is tiptap bug, but when passing parseOptions only during initialization, whitespaces are not preserved,
This can be simply reproduced:

  • create editor with parseOptions initialization:
this.tiptapEditor = new Editor({
  ...
  parseOptions: {
    preserveWhitespace: 'full',
  },
  ...
  • create form with string containing spaces
formGroup: FormGroup = this.fb.group({text: ['<p>a    b  c    d</p>']});
  • tiptap displays value without spaces
<div contenteditable="true" role="textbox" translate="no" class="tiptap ProseMirror" tabindex="0">
  <p>a b c d</p>
</div>

when i create custom tiptap directive, based on editor.directive.ts, only add third param to the setContent method, then tiptap preserves spaces:

<div contenteditable="true" role="textbox" translate="no" class="tiptap ProseMirror" tabindex="0">
  <p>a    b  c    d</p>
</div>

@sibiraj-s
Copy link
Owner

Can you raise an issue in the TipTap repository to get this clarified? If that is how it should be done we can fix it.

@vlad-kuz
Copy link
Author

Started discussion ueberdosis/tiptap#5933

@sibiraj-s
Copy link
Owner

Thanks @vlad-kuz for creating the discussion. It am running on some tight deadline items, so I couldn't reach and follow up with tiptap myself

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants