0

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?

3
  • Exactly what are you expecting, what are you seeing, and what is the code responsible for making you see it like you are? Commented Dec 12, 2012 at 12:23
  • 2
    saying something completely without seeing a single line of code is always difficult. What do you have? How does it look like currently? How is it supposed to look like? Commented Dec 12, 2012 at 12:24
  • Did you try just wrapping the text in PRE tags? Commented Dec 12, 2012 at 12:26

1 Answer 1

1

Put your text into a pre block and it will preserve formatting:

document.getElementsByTagName("pre")[0].textContent = "string1\n\tstring2";


string1
    string2
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.