sudo aptitude update
sudo aptitude install highlight
The program highlight assumes the language based upon the file extension such as *.css, *.html, *.hs, *.java, *.c etc.. If you need to force a language extension use the -S flag.
Console
Now to practice using highlight on some source files.
highlight -A myfile.java | less -R
The flag will turn on ansi colors for the console. Remember to use -R on less or you will have all the escape sequences. This is great when you want to do a quick dump on a source file.
Web Pages
To create the code for this webpage I typed on the following three files qsort.c, qsort.java, qsort.hs.
highlight *.c *.java *.hs
I received the following three files qsort.c.html, qsort.java.html, qsort.hs.html and highlight.css. If you want inline css you can simple use --inline-css.
I got the following web content:
Adding to Blogger
For my blog I added the following to my blogger HTML Template:
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js' type='text/javascript'></script>
<script src='https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/jquery-ui.min.js' type='text/javascript'></script>
<link href='http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/themes/cupertino/jquery-ui.css' rel='stylesheet' type='text/css'/>
You can substitute the theme of cupertino to base or whatever ui-theme you wish. Thanks to Google I can use their jqueryui to host the java script pages.
I don't have web host location so I had to do internal css for the highlight.css file.
<style type='text/css'>
body.hl { background-color:#ffffff; }
pre.hl { color:#000000; backgroud-color:#ffffff; font-size:10pt; font-family:'Courier New';}
.hl.num { color:#2928ff; }
.hl.esc { color:#ff00ff; }
.hl.str { color:#ff0000; }
.hl.dstr { color:#818100; }
.hl.slc { color:#838183; font-style:italic; }
.hl.com { color:#838183; font-style:italic; }
.hl.dir { color:#008200; }
.hl.sym { color:#000000; }
.hl.line { color:#555555; }
.hl.mark { background-color:#ffffbb;}
.hl.kwa { color:#000000; font-weight:bold; }
.hl.kwb { color:#830000; }
.hl.kwc { color:#000000; font-weight:bold; }
.hl.kwd { color:#010181; }
</style>
<script>
I did inline javascript for the same reason as inline css. I don't have web host location. I selected only one ui-theme and added this to my header.
<script>
$(document).ready(
function() {
$("#accordion").accordion({
collapsible: true,
autoHeight: false,
navigation: true
});
}
);
</script>
Finally to add the effect I added the raw HTML
<div id="accordion">
<h3><a href="#">Java</a></h3>
<div>//pasted html from qsort.java.html</div>
<h3><a href="#">C</a></h3>
<div>//pasted html from qsort.c.html</div>
<h3><a href="#">Haskell</a></h3>
<div>//pasted html from qsort.hs.html</div>
</div>I hope to see lots of good looking coding blogs in the near future :)
No comments:
Post a Comment