Syntax highlighting

in Ideas and script requests
Subscribe to Syntax highlighting 19 posts, 5 voices



miksago Scriptwright

This is something that would make a great developer tool/ userscript. Syntax highlighting for all files, eg.
- If you visit a .js file then it displays the code with syntax highlighting
- If you view a page with a code tag on it, then it displays syntax highlighting.

The idea for this userscript came about when i stumble upon: http://softwaremaniacs.org/soft/highlight/en/
I'd really like to see this built by someone, i had a go, but my lack of javascript/greasemonkey knowledge led to failure.

--Miksago

 
Alan K Scriptwright

Shouldn't be hard, and its an awesome idea. I'll look at it.

 
Alan K Scriptwright

I posted an attempt, but it stopped working :(

 
miksago Scriptwright

what do you mean, it stopped working?

 
Alan K Scriptwright

I thought I had correctly modified it, but it only worked on my test page and nowhere else. I have to include the style information as well. I will get back to this asap.

 
Joel H Scriptwright

Alan and miksago,

I took a look at the script from the link and the CSS issue Alan seemed to have. The original script only needed its initialization function called to run. The issue with the CSS is that the original script didn't have any. That's right, the CSS was located in their test.html file. A few calls to GM_addStyle fixed that. I then added a few comments. The end result is at http://userscripts.org/scripts/show/7982

Thanks for the idea and resources for this script; I think it'll help a lot of us code monkeys quite a bit.

 
miksago Scriptwright

None of the above seem to work for me... which is kinda odd.. maybe i could see your test page to check..

 
Alan K Scriptwright

Yes, i figured out that was where the CSS was, i just didnt get around to adding to to the script. btw, it still doesn't work on my test page...

 
Adrian Scriptwright

I'm getting an error all over the place when I try to use this script:

Error: unterminated string literal
Source file: file:///.../gm_scripts/syntaxhighlighter.user.js
Line: 39

It seems like whatever editor you've been using is auto-wrapping the lines. Whenever I fix one error, another one pops up further down.

 
Joel H Scriptwright

Adrian,

It looks like you're right. I had copied and pasted into the text box as the method of uploading the script. I re-uploaded the script by file selection instead, uninstalled my copy of the script, and reinstalled from the site. It works with the test HTML I provided. Sorry for the mistake; I will be sure to use this method of upload exclusively in the future.

-Joel

 
Adrian Scriptwright

Has anyone reported this as a bug to us.o?

 
Henrik N Admin

Added ticket, thanks: http://userscripts.devjavu.com/projects/userscr...

 
Alan K Scriptwright

It still only partially works on my test code

 
Joel H Scriptwright

Alan,

My first guess is that only the HTML and CSS are highlighting; this is the default mode. The first line of executable code looks like:
initHighlightingOnLoad('html', 'css');
Change the parameters to your choice of the nearby list, or no parameters for all of them.

If that doesn't solve the issue, I'll need more details, such as javascript console errors or a better description of what's happening or which code types aren't working and how they're not working.

-Joel

 
Adrian Scriptwright

Hm, I took a look at this code, and right now it's got a few quirks in it. It seems to only work on:
<pre><code>codegoeshere()</code></pre>
So I had to modify a few things on it to get it to work. Here's a patchfile, so you can see what I did.

I wasn't able to get it to work on text pages, such as the "View Script Source" pages on us.o, even though they use <pre> tags, it won't seem to let me change anything...

 
Henrik N Admin

Adrian: Currently, "View Script Source" just outputs the source with the MIME type text/javascript. Eventually we'll probably wrap it in a HTML page (and add an install button and syntax highlighting). Any markup you might see is due to Firefox, and I suppose the GM extension doesn't run on those kinds of pages.

 
Alan K Scriptwright

Joel: That was it. I assumed you had set it up to highlight all. Should have looked at the code.

 
Alan K Scriptwright

Adrian, that is because it is a text file, like Henrik said. It would have to be wrapped in an HTML page in order for CSS styles to be applied to it.

 
Joel H Scriptwright

Alan,

If this is a point of confusion, perhaps I should default it to all. The reason I removed most of them is that the more obscure languages (such as delphi) are still checked, and I noticed it slowing down one of my older computers. Not terribly much, but since this is also set up by default to run on all pages, it annoyed me enough that I changed it.

-Joel

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel