Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7667219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:02:42+00:00 2026-05-31T15:02:42+00:00

I have a UTF8 text string that I would like displayed in a div

  • 0

I have a UTF8 text string that I would like displayed in a div (or the entire <body>) in a web page according to the following rules:

  • All characters should be shown literally as they would in a unicode-aware text editor.

  • Whitespace should not be ignored. TABs should indent to some number of spaces (4 or 8 for example). LFs should cause a line break.

  • Text should be automatically word wrapped (as it would for a normal <p> paragraph, or as it would in a text editor with word wrap turned on) as the width of the containing div of the text file changes.

Clearly I need to perform some preprocessing steps on the text string before I insert it into the web page (perhaps I need to replace certain characters with named entities &foo;. Perhaps I need to surround the text file with a certain tag, <pre> for example, etc).

Precisely what preprocessing steps do I need to perform to achieve the above. If there are multiple sets of steps that achieve the above, than please answer with the shortest/simplest.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:02:44+00:00Added an answer on May 31, 2026 at 3:02 pm

    (1) and (3) are actually quite simple, if you serve your document as UTF-8 and you’re fine with supporting IE >= 8. Then it’s:

    <body style="white-space: pre-wrap">
      (Your String here, '<' and '&' encoded to '&lt;' and '&amp;' respectively)
    </body>
    

    The white-space CSS property is the key here.

    For (2) you will either need a pre-processing step (a la s/\t/ /g) or wait until all browsers support tab-size.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem that output string must be utf8-formatted, I am writing currently
I have a document that has two content types: text/xml and text/html. I would
I have the following xml that's sent to me from a web service. I'm
I have an xml that has nested tags like the following: <?xml version=1.0 encoding=utf-8
I have characters like these on our web site: Fémnyomó That is a street
I have a text file that is encoded in UTF-8. I'm reading it in
I have an XSD file that is encoded in UTF-8, and any text editor
I have a Ruby script that generates a UTF8 CSV file remotely in a
I have the following issue with a UTF8 files structured as following: FIELD1§FIELD2§FIELD3§FIELD4 Looking
I have the following code to encrypt a value (listed below). Now I would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.