.gsub( /\n/, "\n\r" ) not working in WebDialog
-
Strange thing I don't grasp:
htmlCode = %{ <html> test </html>} win = UI::WebDialog.new( "" ) win.set_html( htmlCode.gsub(/\n/,"\n\r") ) win.show p htmlCode[7]When I right-click the WebDialog on Windows 7 selecting "View source", notepad opens and shows no new-lines or carriage-returns, so everything is on 1 line like this:
<html> test</html>
Although selecting this and copy/paste it here or in notepad++ does show new-lines and carriage-returns like:
%(#0000FF)[<html>
test
</html>]It is solved when I add a \n after each line in %{...}
although the Ruby Console is showing a 10, telling me there is alreeady a newline, \n
So why doesn't .gsub(/\n/,"\n\r") work?!Another test shows .gsub(/\n/,"\n\r") is working, only not in the WebDialog !!!
"<html>\ntest</html>".gsub(/\n/,"\n\r")[7] 13
while this still shows 1 line in Notepad with "View source"
win = UI::WebDialog.new( "" ) win.set_html( "<html>\ntest</html>".gsub(/\n/,"\n\r") ) win.show -
gsubcreates a NEW string. It does not change the source string.use
gsub!instead, like:htmlCode = %{ <html> test </html>} win = UI;;WebDialog.new( "" ) htmlCode.gsub!(/\n/,"\n\r") win.set_html( htmlCode ) win.show p htmlCode[7]htmlCode.gsub!(/\n/,"\n\r")
is the similar to:
htmlCode = htmlCode.gsub(/\n/,"\n\r")
... except that immediate methods (names ending with**!**,) returnnilif no changes are made,... so do not use them in an assignment expression.
-
Another thing, in HTML use a
%(#8000BF)[<BR>]tag to cause a linebreak, not "\n". -
@dan rathbun said:
... except that immediate methods (names ending with
**!**,) returnnilif no changes are made,... so do not use them in an assignment expression.This is such an annoying behaviour of Ruby. Source of so many creeping bugs.
-
Enclosing <p> tags in html should recognize new lines in the html's text, and reflect that in what is displayed.
Or as Dan says add <br> to force a new line in what is displayed...
A \n will not work within html like you expected...Incidentally, do you have your rb files' encoding set to 'UTF-8 without BOM' ?
You ought to...
Notepad++ has easy options to re-encode existing ANSI files... and you can set the exe's options to make all new text files 'UTF-8 without BOM' anyway... -
Thank you all.
However gsub! isn't the solution, still shows everything on one line in notepad!
I know <br> is the new-line in html, but I'd like to give out a html that also has new-lines using "View source" in notepad. Makes it more readable
But I've found the problem so it is solved

It's stupid but I should have used.gsub(/\n/,"**\r\n**")not.gsub(/\n/,"**\n\r**") -
Yea, Notepad is fuzzy about new lines.
-
So this time it's not SU Ruby but MS-Windows

-
@onidarbe said:
So this time it's not SU Ruby but MS-Windows

NotePad sucks.
To set View Source to Notepad++ run the reg file for your Windows bitsize:
(choose 32bit or 64bit Windows)If you installed Notepad++ to a custom location, you will need to edit the regfile !
-
Thanks Dan!
But in this case I want for those maybe using my stuff to make it readable in notepad to

Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement