Since Kerm is taking forever to add code prettifier to cemetech ( http://google-code-prettify.googlecode.com/svn/trunk/README.html ), I went and did it myself in the form of a greasemonkey script.

Screenshot of it in action:


Install: <no longer needed, but link below if you are interested in seeing how it worked>
http://kllrnohj.com/userscripts/codeprettifier.user.js
(You need greasemonkey to use the above, get it here: https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/ )
For Chrome users, it works without Greasemonkey. However, you can't specify what sites it'll work on. So upon installation of the extension, it'll inform you that it has access to your data on all websites :/ (updated)

Image no longer valid.

In Greasemonkey it's at least easy to change what sites will run the javascript or not.

Kllrnohj, anyway you can specify what site(s) the javascript can run on?
comicIDIOT wrote:
Kllrnohj, anyway you can specify what site(s) the javascript can run on?


It already does



EDIT: Updated with the chrome-specific addition needed. Stupid Chrome wants it to be @match instead of @include because who the hell knows why.
It works fine in Opera, too, though it only appears to run after document onload rather than on DOMContentLoaded. Renaming it .js (rather than .user.js) and wrapping the whole thing in window.addEventListener('DOMContentLoaded', function() { /* ... */ }, false); seems to do the trick, though. Smile Good work!
Prettify added, and after some arm wrestling, set to monospaced font, too.
Kllrnohj, appreciate the update.

Here's some code to see if it works for people:


Code:
static void writeTree(XmlNode xmlElement, int level) {
   String levelDepth = "";
   for(int i=0;i<level;i++)
   {
      levelDepth += "   ";
   }
   Console.Write("\n{0}<{1}",levelDepth,xmlElement.Name);
   XmlAttributeCollection xmlAttributeCollection = xmlElement.Attributes;
   foreach(XmlAttribute x in xmlAttributeCollection)
   {
      Console.Write(" {0}='{1}'",x.Name,x.Value);
   }
   Console.Write(">");
   XmlNodeList xmlNodeList = xmlElement.ChildNodes;
   ++level;
   foreach(XmlNode x in xmlNodeList)
   {
      if(x.NodeType == XmlNodeType.Element)
      {
         writeTree((XmlNode)x,  level);
      }
      else if(x.NodeType == XmlNodeType.Text)
      {
         Console.Write("\n{0}   {1}",levelDepth,(x.Value).Trim());
      }
   }
   Console.Write("\n{0}</{1}>",levelDepth,xmlElement.Name);
}
http://www.fincher.org/tips/Languages/csharp.shtml
Looks like it's working to me! Very Happy


Code:
#include <iostream.h>

// sequence is 0, 1, 1, 2, 3, 5, 8, 13, ...

int fib (int i) {
  int pred, result, temp;
 
  pred = 1;
  result = 0;

  while (i > 0) {
    temp = pred + result;
    result = pred;
    pred = temp;
    i = i-1;
  }
  return(result);
}

int main () {
  int n;
  cout << "Enter a natural number: ";
  cin >> n;
  while (n < 0) {
    cout << "Please re-enter: ";
    cin >> n;
  }
  cout << "fib(" << n << ") = " << fib(n) << endl;
  return(0);
}
http://www.cs.indiana.edu/~sabry/teaching/intro/fa96/code/fib.C
benryves wrote:
It works fine in Opera, too, though it only appears to run after document onload rather than on DOMContentLoaded. Renaming it .js (rather than .user.js) and wrapping the whole thing in window.addEventListener('DOMContentLoaded', function() { /* ... */ }, false); seems to do the trick, though. Smile Good work!


Actually, Chrome runs the script in document-idle (which could be before or after window.onload) and Greasemonkey runs it at document-end (before window.onload).

My script doesn't care when it runs, so long as the DOM has been parsed (so at least after document-end).

KermMartian wrote:
Prettify added, and after some arm wrestling, set to monospaced font, too.


That is what the <code> tag does Razz
Kllrnohj wrote:
KermMartian wrote:
Prettify added, and after some arm wrestling, set to monospaced font, too.


That is what the <code> tag does Razz

You would think so, but I have a global font-family override to Verdana, which makes things sad.
KermMartian wrote:
You would think so, but I have a global font-family override to Verdana, which makes things sad.


You also have a table-based layout, which makes baby jesus cry.
Kllrnohj wrote:
KermMartian wrote:
You would think so, but I have a global font-family override to Verdana, which makes things sad.


You also have a table-based layout, which makes baby jesus cry.
Every time I do a pure-div based layout, I eventually get to the point where it's so stupidly overcomplex than I throw in the towel, save myself hours of insanity, and use a table.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement