Post: NGU Syntax Highlighter [USERSCRIPT]
01-11-2016, 11:47 PM #1
Specter
Pro Memer
(adsbygoogle = window.adsbygoogle || []).push({}); Note: This was primarily targeted to work with C/C++, it should work generally for other languages like Python, but some things aren't implemented, and most code posted in threads is C/C++ related anyway.

I've realized (and probably many others) that the lack of syntax highlighting in [CODE] bbcode tags can get annoying and unreadable at times. So after a few times of You must login or register to view this content., I decided to make a monkeygrease/tampermonkey userscript that would use regex (I hate regex but gotta admit it's useful), and would do at least some sort of syntax highlighting. Now it's not a full-blown all-out IDE-level syntax highlighter, but I feel it's sufficient for snippets of codes in threads and such. There may be a few bugs, however I didn't encounter many major ones in the final script. I tested it out on my You must login or register to view this content..

You must login or register to view this content.
Yes I'm aware it will do it to text that is not in the code tags but also in the general thread, but generally the text that gets replaced isn't used too often other than code references, so it's kind of good in a way anyway, and it will only do this if code tags are present in the thread.

Now the pop-up just lets you know that syntax-highlighting will take place and was also there for me in early stages for development, you're free to remove it if you'd like. You're free to edit and redistribute the script, however if you don't know anything about regex then you might not want to mess with things as it'll break the whole thing. The reason there might be small bugs or you might go through the script and go "what the hell was he thinking?", it's because certain things I had to use a work-around for a few things so it wouldn't interfere with NGU source-code, otherwise it'll cause things like the ultimate fail I posted above.

It basically just detects if the thread uses any code tags and if it does applies replaces to certain texts such as data-types so the html includes color.

The code is commented slightly, but it isn't documented too well and I didn't take a whole lot of time to format it and make it look pretty, but it should work. For mozilla, just use the page provided and install, for chrome, switch to the "Code" tab, install the tampermonkey extension and add it in there. If you wish to make improvements or innovate on it, go right ahead.


You must login or register to view this content.
Last edited by Specter ; 01-11-2016 at 11:53 PM.

The following 3 users say thank you to Specter for this useful post:

Crunk, Helping-Hand, Kam
01-11-2016, 11:51 PM #2
Blessings
Do a barrel roll!
Nice share! Very useful. Smile
01-11-2016, 11:54 PM #3
Crunk
Sir, I'm too 1337
Originally posted by Specter View Post
Note: This was primarily targeted to work with C/C++, it should work generally for other languages like Python, but some things aren't implemented, and most code posted in threads is C/C++ related anyway.

I've realized (and probably many others) that the lack of syntax highlighting in [CODE] bbcode tags can get annoying and unreadable at times. So after a few times of You must login or register to view this content., I decided to make a monkeygrease/tampermonkey userscript that would use regex (I hate regex but gotta admit it's useful), and would do at least some sort of syntax highlighting. Now it's not a full-blown all-out IDE-level syntax highlighter, but I feel it's sufficient for snippets of codes in threads and such. There may be a few bugs, however I didn't encounter many major ones in the final script. I tested it out on my You must login or register to view this content..

You must login or register to view this content.
Yes I'm aware it will do it to text that is not in the code tags but also in the general thread, but generally the text that gets replaced isn't used too often other than code references, so it's kind of good in a way anyway, and it will only do this if code tags are present in the thread.

Now the pop-up just lets you know that syntax-highlighting will take place and was also there for me in early stages for development, you're free to remove it if you'd like. You're free to edit and redistribute the script, however if you don't know anything about regex then you might not want to mess with things as it'll break the whole thing. The reason there might be small bugs or you might go through the script and go "what the hell was he thinking?", it's because certain things I had to use a work-around for a few things so it wouldn't interfere with NGU source-code, otherwise it'll cause things like the ultimate fail I posted above.

It basically just detects if the thread uses any code tags and if it does applies replaces to certain texts such as data-types so the html includes color.

The code is commented slightly, but it isn't documented too well and I didn't take a whole lot of time to format it and make it look pretty, but it should work. For mozilla, just use the page provided and install, for chrome, switch to the "Code" tab, install the tampermonkey extension and add it in there. If you wish to make improvements or innovate on it, go right ahead.


You must login or register to view this content.


This. This is glorious.
01-11-2016, 11:55 PM #4
Slick
Anxiety
Thanks, Mr. Spec! Enzo

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo