Saturday, 11 January 2014

Code snippets in Dynamic views on blogger

Add the following code to the beginning of the <head> section in the blogger template
<link 
href="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.css"
type="text/css"
rel="stylesheet"/>
<script type="text/javascript"
src="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js">
</script>
Add the following code to the end of the <head> section in the blogger template
 
<script>
$(window.blogger.ui()).on('viewitem', function (event, post, element) {
element.each(function () {
// first argument is a callback function
// second argument is a root element or document to check
prettyPrint(null, this);
});
});
</script>
Then add <pre class="prettyprint"> to the beginning of a code section in the post, and close the code section with </pre> to get this:
  

/*Blink (Arduino)
Turns on an LED on for one second, then off for one second, repeatedly.

This example code is in the public domain.
*/

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

No comments:

Post a Comment