Hi Ričardas,
I think out-of-box it is not available because I tried below setting in the initialization module but it seems like it is not supported.
.AddSetting("apply_source_formatting", true);
Honestly, if keeping the formatting is important using a WYSIWYG like TinyMCE probably isn't the way to go.
Found this old (2011!) TinyMCE forum post that gives some of the reasons why:
Preserving white space in a rich text editor will never work. Just think about it, it would need to have some form of AI to figure out how the current document is formatted with white space and depending on that format apply the same indentation to new contents of the same type or it will be completely random behavior existing contents would be indented for a while until you modify it.
So it's better to just normalize the whitespace/formatting so that it will always be produced in the same way. We do that by removing all white space before after block elements and some whitespace that is redundant then re-apply line feeds before/after block elements. We don't indent with tabs/spaces since it would produce way to much HTML code for storage. We might add some plugin for that in the future that does the extra indentation.
Best regards,
Spocke - Main developer of TinyMCE
You could apply some beautification before rendering, but that won't preserve the entered code.
Hi all,
is it possible to preserve code formatting in TinyMCE Source Code mode, example image - https://i.imgur.com/xu446dm.png
Cheers, thanks!