Wednesday, 22 February 2023

Blogger - Formatting code in to a post so it keeps its format

After so long putting scripts on this site, I finally got annoyed enough to actually figure out how to do it.

Its a bit long winded but seems to work.  first at the top left change the view to <>HTML View, then type the following

<pre>
<code>

Code and formatting goes here

</code>
</pre>

Blogger should then display the code as you enter it.  you can then switch back to compose view and write normally

you may also need to put the following in to your HTML theme too to get it to wrap

pre, code {
 padding:5px;
 box-sizing:border-box;
 -moz-box-sizing:border-box;
 webkit-box-sizing:border-box;
 display:block; 
 white-space: pre-wrap; 
 white-space: -moz-pre-wrap;
 white-space: -pre-wrap; 
 white-space: -o-pre-wrap; 
 word-wrap: break-word; 
 width:100%; overflow-x:auto;
}

No comments:

Post a Comment