Simple Programming Language Code Syntax Highlighter with JavaScript

Highlighting the source codes is one very great and important functions for the website/blog that mainly shows source codes on the web pages, jsB@nk also presented you many source code syntax highlighting tools, web applications, code syntax highlighters through two JavaScript article tutorial:

- Highlight your PHP and JavaScript codes with PHP highlight_string
- 16 Free Code Syntax Highlighters by Javascript For Better Programming

Really I also had the plan to apply this cool and amazing feature to jsB@nk since two years ago, however I still could not do this intent cause of many objective reasons. But now, I'm pleasure and happy to show you new JavaScript code example for highlighting your source codes. Although it's quite simple (just compared with other highlighting tools above) but they can still work very well for all programming languages.


Sampled by © JavaScriptBank.com
JavaScript
/**
 * nth element in the fibonacci series.
 * @param n >= 0
 * @return the nth element, >= 0.
 */
function fib(n) {
  var a = 1, b = 1;
  var tmp;
  while (--n >= 0) {
    tmp = a;
    a += b;
    b = tmp;
  }
  return a;
}

document.write(fib(10));
PHP
<html>
  <head>
    <title><?= 'Fibonacci numbers' ?></title>

    <?php
      // PHP has a plethora of comment types
      /* What is a
         "plethora"? */
      function fib($n) {
        # I don't know.
        $a = 1;
        $b = 1;
        while (--$n >= 0) {
          echo "$a\n";
          $tmp = $a;
          $a += $b;
          $b = $tmp;
        }
      }
    ?>
  </head>
  <body>
    <?= fib(10) ?>
  </body>
</html>
HTML
<html>
  <head>
    <title>Fibonacci number</title>
  </head>
  <body>
    <noscript>
      <dl>
        <dt>Fibonacci numbers</dt>
        <dd>1</dd>
        <dd>1</dd>
        <dd>2</dd>
        <dd>3</dd>
        <dd>5</dd>
        <dd>8</dd>
        …
      </dl>
    </noscript>

    <script type="text/javascript"><!--
function fib(n) {
  var a = 1, b = 1;
  var tmp;
  while (--n >= 0) {
    tmp = a;
    a += b;
    b = tmp;
  }
  return a;
}

document.writeln(fib(10));
// -->
    </script>
  </body>
</html>
In Sentences

Lorem ipsum dolor sit amet, <script type="text/javascript"> consectetuer adipiscing elit. Ma quande function lingues() coalesce, li grammatica del resultant.


2000+ free JavaScripts
at www.JavaScriptBank.com