Mar 6, 2013 02:21 AM
(This post was last modified: Mar 6, 2013 11:38 AM by ~Dec.)
Click this link to download the userscript.
I'm frustrated with the current way code blocks function on HackForums. Are you as well? If so, read further.
I made a suggestion regarding code tags and some improvements - and Omni posted without rejecting it, which is great news. It might be a while before it's implemented though (and I may have to help) - but in the meantime, I have created a Userscript that somewhat improves upon what we currently have. Basically, it turns the crappy code tags into better ones, with support for 54 languages and automatic syntax detection.
Description:
This script will turn the plain old boring and functionless [code] and php tags on HackForums.net into more informative counterparts of themselves that match the theme of the site.
Features support syntax highlighting for over 50 languages (instead of just PHP), a select all button to highlight all of the code within a block, an 'expand' button to extend the height of the code block to the full length of the code and automatic syntax detection.
The automatic syntax detection is not entirely accurate, as it uses a heuristic algorithm to detect keywords unique to each language - the language with the most keywords wins. Very often you will see the wrong language highlighted, but not all the time. This is still better than only having it highlight PHP.
In the future, I might add a means of manually setting the language in - but for now I've done enough coding on this script.
Unfortunately, I have yet to find a solution to the indentation problems with the [code] tags. For now, consider using 2-space indentation a best practice. Also, there is no way to fix the truncation of repeated text nodes, so do not bother me about it.
New in v1.0.1
I've updated the userscript to allow manual syntax highlighting when it isn't smart enough to detect the correct language. This is done in the form of a comment on the first line of the code block with a flag - "this.code.is" followed by the CSS class name the highlighter attributes to the language. For example;
If I wanted to make my code Javascript:
// this.code.is javascript
or maybe CoffeeScript:
# this.code.is coffeescript
And so on.
Finding the correct class names for your language might be tricky, so if you're unsure - here's a webpage you can visit: http://softwaremaniacs.org/media/soft/hi.../test.html
The green text on the left of each code block is the CSS class for that language.
Also, I've made the names of some of the languages more concise, for example "AVR Assembler" instead of "AVRASM".
Screenshot of what it does:
I'm frustrated with the current way code blocks function on HackForums. Are you as well? If so, read further.
I made a suggestion regarding code tags and some improvements - and Omni posted without rejecting it, which is great news. It might be a while before it's implemented though (and I may have to help) - but in the meantime, I have created a Userscript that somewhat improves upon what we currently have. Basically, it turns the crappy code tags into better ones, with support for 54 languages and automatic syntax detection.
Description:
This script will turn the plain old boring and functionless [code] and php tags on HackForums.net into more informative counterparts of themselves that match the theme of the site.
Features support syntax highlighting for over 50 languages (instead of just PHP), a select all button to highlight all of the code within a block, an 'expand' button to extend the height of the code block to the full length of the code and automatic syntax detection.
The automatic syntax detection is not entirely accurate, as it uses a heuristic algorithm to detect keywords unique to each language - the language with the most keywords wins. Very often you will see the wrong language highlighted, but not all the time. This is still better than only having it highlight PHP.
In the future, I might add a means of manually setting the language in - but for now I've done enough coding on this script.
Unfortunately, I have yet to find a solution to the indentation problems with the [code] tags. For now, consider using 2-space indentation a best practice. Also, there is no way to fix the truncation of repeated text nodes, so do not bother me about it.
New in v1.0.1
I've updated the userscript to allow manual syntax highlighting when it isn't smart enough to detect the correct language. This is done in the form of a comment on the first line of the code block with a flag - "this.code.is" followed by the CSS class name the highlighter attributes to the language. For example;
If I wanted to make my code Javascript:
// this.code.is javascript
or maybe CoffeeScript:
# this.code.is coffeescript
And so on.
PHP Code
<?php
// this.code.is php
PHP Code
<?php
// this.code.is javascript
PHP Code
<?php
# this.code.is coffeescript
PHP Code
<?php
// this.code.is cpp
Finding the correct class names for your language might be tricky, so if you're unsure - here's a webpage you can visit: http://softwaremaniacs.org/media/soft/hi.../test.html
The green text on the left of each code block is the CSS class for that language.
Also, I've made the names of some of the languages more concise, for example "AVR Assembler" instead of "AVRASM".
Screenshot of what it does:
[img]http://i.imm.io/Yl6d.png[/img]


![[Image: 2QzRqrh.png]](https://i.imgur.com/2QzRqrh.png)

