Monday, August 10, 2015

Adding code to a HTML page

If any noobie is looking for tips to publish their code on their blog or webpage, here it is:

STEP 1:
Go to the HTML editor (Click on the HTML button in the top left corner,next to the Compose button for blogspot)

STEP 2:
Add the below in the before </div> tag:
<code>
<pre>
</pre>
</code>

STEP 3:
Add code (Java, C, HTML, blah, blah ,blah) after <pre> tag and before the closing </pre> tag.

CHECK:
This is how it should look finally, before you publish:

<div dir="ltr" style="text-align: left;" trbidi="on">
<code>
<pre>
Collection<String> generateRandomStrings(int numberOfStrings)
{
List<String> wordList = new ArrayList<String>();
return wordList;
}
</pre>
</code>
</div>

Update: Always make sure there is a space after <, if you're using it for comparison operations. Otherwise blogspot appears to throw an error. Why? I need to explore.


No comments:

Post a Comment