Code written directly in an Article will loose it’s formatting. The code will be written all in one line losing its code format structure. In order to maintain the code formatting, you can do the following:
In Visual editor
Select the block of code and press the code wrap button
In Text Editor
Select the block of code and press the ‘code snip’ or ‘code block’ button
or wrap your block of code manually in ‘code’ or ‘pre’ tags in the Text editor.
Code Snip vs Code Block
Using the ‘code snip’ button or adding the ‘code’ tags are used for embedding code that is displayed in one line. Using the ‘code block’ button or adding the ‘pre’ tags are used for embedding blocks of code that are written in more than one line.
Example of how the embedded code will appear:
alert('What is your name?');
Code snip or code wrapped in ‘code’ tags
function buttonClick(){ alert('Button has been clicked'); }
Code block or code wrapped in ‘pre’ tags
*Please note that executable codes or scripts such as javascript, jQuery, php, java, C+, etc. that are embeded in articles are not executed and are for display purposes only.