FunctionallyReactive
FunctionallyReactive

Reputation: 579

Need to display Text formatted data in HTML webview like Stack Overflow

I have plain text data that is formatted in terms of spacing lines etc. But I would like to display this text as HTML? How can this be done.

[American Thinker]

 March 1, 2016
 [American Thinker] [Navigation Menu]
 HomeArchivesVideoCartoonsAboutSearchLoginRules/FAQContactDonations
 Merchandise <http://www.americanmethod.com/american-thinker/>
 Home Archives Video Cartoons About Search Login More [Down Arrow]
   * Rules/FAQ
   * Contact
   * Donations
   * Merchandise <http://www.americanmethod.com/american-thinker/>


 American Thinker Blog

 Mexican oil giant devastated by oil price decline - 3/1/16 March 1, 2016 
 The state owned oil company that provides one third of the revenue of the 
 Mexican government is in a deep crisis, owing to low oil prices, 

I would like to display just like in it appears here on stackoverflow on the web.

The problem is that when I put it in say a paragraph it looks all strung together.

The opposite operation Html.fromHtml(htmlString) is supported, but how do I convert the text to something that displays correctly in HTML? Did not think of it till I posted but really want it to look just like this edit text.

UPDATE:

    <PRE> </PRE>  

Does some of what I want but now wrapping does not occur so have to scroll right or left.

UPDATE: Adding as per suggestion below I now get sentence wrapping, but some lines like the following:

    The state owned oil company that
    provides one third of the revenue of                                      
    the
    Mexican government is in a deep crisis,
    owing to low oil prices,
    inefficiency, and corruption. The
    implications for the United States are
    important.  More
    The Calamitous Climate at
    etc etc

Here is my html:

       String htmlstuff = " \n" +
              "<html>\n" +
              "<header><title>This is title</title></header>\n" +
              "<body>\n" +


        "<pre style=\"white-space: pre-wrap;\">\n";

        htmlstuff=htmlstuff+result;
        htmlstuff=htmlstuff+
                " </pre>\n"+

              "</body>\n" +
              "</html>\n";
        wv.loadDataWithBaseURL("", htmlstuff, "text/html", "UTF-8", "");

        wv.setHorizontalScrollBarEnabled(false);

Upvotes: 3

Views: 1012

Answers (1)

Rehan Haider
Rehan Haider

Reputation: 1061

Consider this Html display formatted text

You just have to place your text between

<pre>

tag and use CSS's

white-space: pre-wrap;

property to show it without horizontal scroll like this

<pre style="white-space: pre-wrap;">
  Formated text
  Line 2      with wide spaces
  Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
</pre>

Upvotes: 3

Related Questions