Reputation: 93
Recently I wrote a simple webapp for handling telnet connections with routers. I am using Node.js with Express and WebSockets. After setting up a connection, a stream from terminal goes through websocket as UTF-8 string.
And here is my problem: I wrote a simple displaying function that uses slice('\n')
and adds an html paragraph, but I'm not satisfied with results, everything is a mess (towel.blinkenlights.nl telnet-based Star Wars doesn't look even close to the version from terminal). When I display the data in the browser console it looks fine, but in my html it does not.
The main problem is probably caused by these all \n
's \t
's etc.
So now I'm looking for a solution/library/something that converts js string to html markup. Is there anything like that, maybe in jQuery or so?
Upvotes: 0
Views: 209
Reputation: 32598
Put your text into a pre
block and it will preserve formatting:
document.getElementsByTagName("pre")[0].textContent = "string1\n\tstring2";
string1
string2
Upvotes: 1