I am using SyntaxHighlighter on my website and it is acting very strange. I put my codes in <pre>s and used SyntaxHighlighter.all(), and what I got are in every single codes, it inserted 1~2 extra lines.
Where's the problem? I checked everything and everything is fine. Please help.
I don't know about SyntaxHighlighter, but in general, the <pre> tag works effective immediately, LF and CR everything. When Syntax Highlighter does its conversion, it might be respecting these line feeds as well. For example:
<pre>
There will be a line before and after this
</pre>
vs.
<pre>There will be no lines</pre>
We're used to writing well-formatted and well-indented code, but with pre tags you have to make an exception. Looking at your source code, I think you're doing it the top way.
Related
I don't see a way to change indentation unit to two-space or best, make it automatically detect the unit: http://codemirror.net/mode/python/index.html
As you can see, the if showed read since it got cm-error class. It has two-space indent. But the print is fine. Although this code block works fine.
So:
Is there a way to make the code using two-space indentation?
Is it possible to make automatic indentation unit?
I tried to play around with http://codemirror.net/mode/python/python.js and cannot come up with any conclusion.
See the indentUnit option. There's no auto-detection in the library, but you might be able to write a little script that finds the first line that's indented more than the one above it, and take the difference as a likely guess.
I am struggling with strange behavior of textarea... I am writing small snippet store for my own needs and I would like to paste a code fragment into textarea and then format it using jQuery library, but sometimes I get very strange output (jQuery library is turned off). Screenshot shows it all:
In notepad it looks the way I want it, but in pre tag first line is not indented... Could you explain me why? I am using Ruby and Ruby on Rails if it matters.
Thanks in advance!
So, you're populating the textarea from RoR, right?
I don't suppose it's as simple as your <% %> being on a new line, and then your code indenting adding extra spaces in?
I have a bookmarklet that allows me to wrap any function and insert a debugger statement before it is called.
It works fine, but since the bookmarklet is a single line debugger stops somewhere in the middle of a long string of code and I need to scroll to find the breakpoint.
How can I insert a new line character after the debugger statement so that when it's encountered the code in the console is split into two lines?
The \n and literal newline character copied from a textarea into the bookmarklet don't split lines in the debugger.
Generally, it is best to URL-encode a bookmarklet before storing in a bookmark. So you can have a multiline bookmarklet simply by encoding the newlines, as demonstrated by this: encodeURIComponent("alert('line1');\nalert('line2');")
That answers the question as you asked it, but I'm not sure if this is your real problem. If you provide example code I might be able to give further advice.
No, bookmarklets are always one-liners.
You can use the chrome debugger which has a "prettify code" option.
Another option would be not running it as a normal bookmarklet during debugging but injecting a script tag pointing to a properly formatted version of your script.
I am writing a dynamic webpage that is compiled and dynamically loaded using a C program. I have been writing the code by using:
printf ("<p><h1>Hello world!</h1></p>\n");
I want to add jQuery to the file, so the first thing I did was was a leader back slash to all quotes:
"Text here" becomes \"Text here\"
Now this leaves two problems:
1 - In the JS file, the original code looks like this:
*(?:(['\"])((?:\\\\.|[^\\\\])*?)\\3|("+O+")|)|)"+_+"*
And after the " correction is made looks like this (this is just a sample extract of code):
*(?:(['\\"])((?:\\\\.|[^\\\\])*?)\\3|(\"+O+\")|)|)\"+_+\"*
But a lot of this code is not greyed out (as it should be as I want just the contents of the line printed so the browser knows what to do). I have added some additional \s and made it grey - this appears to work, but still produces some compiling errors.
2 - When I attempt to compile, there are characters (such as \t , \r and /) that are not recongised by the compiler - how can I ensure that these are considered part of the javascript code?
Any help with this would be greatly appreciated.
You also need to escape the backslashes as well, not just the quotes, that should fix both your problems.
So your JS Code should look more like this in the end:
*(?:(['\\\"])((?:\\\\\\\\.|[^\\\\\\\\])*?)\\\\3|(\"+O+\")|)|)\"+_+\"*
I have been looking around for a HTML formatter to incorporate with a project I am doing. I need it to be written in Javascript since I want the formatting done on the client side.
The problem is, the few that I have tried don't work very well... For example:
http://www.davidpirek.com/blog/html-beautifier-jquery-plugin : Has a problem with one of the For loops (in the cleanAsync function). Chrome says "unexpected token ILLEGAL"
JS Beautifier on GitHub : When I have links in the HTML it will put a newline character after it. The problem is, I have a period directly after the link in some cases and it will add a space between the link text and the period in the sentence. I tried poking around to fix it but I could not.
Are there any others, or does anyone have recommendations to fix the above two?
EDIT:
This is for editing code, so I just need something to tab in the lines, etc. The code output will go in a textarea.
A few to look at, all have working demos:
http://alexgorbatchev.com/SyntaxHighlighter/
http://shjs.sourceforge.net/
http://jush.sourceforge.net/
http://dojotoolkit.org/reference-guide/dojox/highlight.html
use https://github.com/beautify-web/js-beautify and pass your code to html_beautify() method.