Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Preserve spacing and indent in TinyMCE Source Code mode

Vote:
 

Hi all,

is it possible to preserve code formatting in TinyMCE Source Code mode, example image - https://i.imgur.com/xu446dm.png

Cheers, thanks!

#222261
May 01, 2020 12:45
Vote:
 

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);

https://www.tiny.cloud/docs-3x/reference/configuration/Configuration3x@apply_source_formatting/#exampleofusageoftheapply_source_formattingoption

#222262
May 01, 2020 13:25
Jake Jones - May 01, 2020 15:31
"(Removed in: 3.0)"

This might be because Episerver is using TinyMCE v4 😉
Vote:
 

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.

#222268
May 01, 2020 15:46
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.