xer21 san
Thanks.
It would be helpful if you could tell Alex(the author of SyntaxHighlighter) about #2 also.
Alex’s site: http://alexgorbatchev.com/SyntaxHighlighter/
xer21 san
Frankly, I can’t understand about #1 issue, becase I haven’t used Visual Studio.
However, Let me know whether it works or not, when you repalce
var code = document.getElementById('shtb_box_code').value.replace(/</g,'<').replace(/\n/g,'<br>');
with
var code = document.getElementById('shtb_box_code').value.replace(/</g,'<');
or
var code = document.getElementById('shtb_box_code').value.replace(/</g,'<').replace(/\r\n/g,'<br>');
var code = code.replace(/\n|\r/g,'<br>');
Sorry, I might misunderstood about #2 issue.
If you set 3.0.38 as “Library version” on the senttig panel,
To copy the code with correct line breaks to the clipboard, you must double-click on the code bolock and copy the code.
Thank you.
Thread Starter
xer21
(@xer21)
redcocker,
Thanks for the reply. As for #1 when you copy from visual studio all new lines are defined with CRLF or in other words, \r\n is the newline identifier. So unfortunitely Alex’s code puts two lines for each 1 newline you paste in. In your code though you can prevent that by checking for [\r]?\n which means \r is optional and it will replace both \r\n and \n with
Oops, the code that got posted from me removed the <br>
so the proper code is
var code = document.getElementById('shtb_box_code').value.replace(/</g,'<').replace(/[\r]?\n/g,'<br>');
Sorry for the confusion on that.
For #2 I’m still messing with that fix that I made because then word wrapping wasn’t working properly after I changed that. Basically what the problem is, I select the text hit ctrl-c to copy the text and when you paste it there is no \n or \r\n so all the text in the box is output as 1 big line.
Thread Starter
xer21
(@xer21)
redcocker,
I checked Alex’s site, and it appears someone provided a fix last month and he merged it with his code. However the build is not updated and I couldnt find the source. They said the fix was in the “shCore.js” file in function eachLine, the fix was to change
return lines.join(‘\n’);
to
return lines.join(‘\r\n’);
but I’m not sure if that will work or not I have not tested it.
xer21 san,
Thank you for your reply.
I finally reproduced #1 issue on Opera 11.
This issue wasn’t caused by CRLF on the Visual Studio.
My javascript code had more serious bug.
When entering your code in the textarea, your browser replaces all line breaks.
Opera 11 for Win32 replaces all line breaks with CRLF.
IE9 for Win32 replaces all line breaks with LF.
This behavior will vary by browser and version.
But I didn’t know about this behavior.
Now I fixed #1 issue and you can download Development Version.
And thank you for the information about #2 issue.
I will wait until the next release of SyntaxHighlighter.
SyntaxHighlighter 1.5.8 released to fix #1 issue.