prevent TinyMCE 5 from removing empty lines before custom paste_preprocess function

41 views Asked by At

How can the input processing be fixed so that line spacing is retained? Using the basic paste plugin.

When pasting this plain text, TinyMCE 5.10.7 (2022-12-06) is removing the empty lines spacing when forced_root_block is set to "div". The lines without alphabet characters should not need a space to keep the line spacing.

a no spaces

b

c

d

The output from the custom paste_preprocess function(plugin, args) { console.log(args.content); }

<div>a no spaces</div><div>b</div><div>c</div><div>d</div>

When forced_root_block is set to "" (empty), the paste_preprocess console.log is the desired value that retains line spacing.

a no spaces<br><br>b<br><br>c<br><br>d

forced_root_block is set to "div" to get formatting and alignment behavior working as expected. Without it, formatting changes apply to more than the selected text.

Is there another hook/event before the input plain text is altered to have HTML?

These are the options I tried:

//   forced_root_block: "div",
  forced_root_block: "",

  paste_preprocess: function(plugin, args) {

    console.log('content before: '+args.content);

    args.content = args.content.replace('<br><br>', '<br> <br>'); // + " regex1";
    args.content = args.content.replace('<br /><br />', '<br /> <br />'); // + " regex2";

    // args.content = args.content.replace(/\n\s*\n/, "\n \n") + " regex 3";

    console.log('content after : '+args.content);

  },
  paste_enable_default_filters: true,
  toolbar: ['undo redo | forecolor backcolor fontsizeselect bold italic underline strikethrough link alignleft aligncenter alignright alignjustify paste pastetext code'],

Other TinyMCE options did not resolve the behavior while keeping forced_root_block set to "div". The plain text toggle did not alter the result in this case.

0

There are 0 answers