Step 1. Add this line of code on your html page or blog page on your header / body.
<script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js?lang=css&skin=sons-of-obsidian"></script>
---------------------------------------------------------------------------
Step 2. You can change the change the style of the code by changing its skin name.
i.e. skin = default, desert, sunburst, sons-of-obsidian, doxy.
<script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js?lang=css&skin=default"></script>
OR
<script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js?lang=css&skin=desert"></script>
OR
<script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js?lang=css&skin=sunburst"></script>
OR
<script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js?lang=css&skin=sons-of-obsidian"></script>
OR
<script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js?lang=css&skin=doxy"></script>
---------------------------------------------------------------------------
Step 3. Now enter this code where linenums means line number and which line number you want your code to start from.
<?prettify linenums=01?>
<pre class="prettyprint">
<<YOUR PYTHON CODE>> // Enter your python code here
</pre>
---------------------------------------------------------------------------
Hope it helps in your blogging.
Happy Blogging.
You can check out the sample code formatting here:-
#!/usr/bin/python
import thread
import time
# Define a function for the thread
def print_time( threadName, delay):
count = 0
while count < 5:
time.sleep(delay)
count += 1
print "%s: %s" % ( threadName, time.ctime(time.time()) )
# Create two threads as follows
try:
thread.start_new_thread( print_time, ("Thread-1", 2, ) )
thread.start_new_thread( print_time, ("Thread-2", 4, ) )
except:
print "Error: unable to start thread"
while 1:
pass
Source:- https://github.com/google/code-prettify
https://github.com/google/code-prettify/blob/master/docs/getting_started.md
