Java HTML to Text toHtmlByPlain(String plainText)

Here you can find the source of toHtmlByPlain(String plainText)

Description

same work with #toHtmlByHtml(String) but think input parameter as plain text (so meaning if there have charactor that cannot convert to html it's will change to other)
Example:
 input: 
I am Java programmer
output: <div>I am <code>Java</code> programmer</div>

License

Open Source License

Parameter

Parameter Description
plainText plain text

Return

input with html, body and head tag

Declaration

public static Element toHtmlByPlain(String plainText) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import org.jsoup.nodes.Element;

public class Main {
    /**//from   w  w  w.  ja  v a 2 s. co m
     * same work with {@link #toHtmlByHtml(String)} <b>but</b> think input parameter as plain text (so meaning if there have charactor that cannot convert to html it's will change to other) <br>
     * Example:
     * <pre>{@code
     * input: <div>I am <code>Java</code> programmer</div>
     * output:
     * <html>
     *      <head></head>
     *      <body>
     *          &lt;div&gt;I am &lt;code&gt;Java&lt;/code&gt; programmer&lt;/div&gt;
     *      </body>
     * </html>
     *  }</pre>
     *
     * @param plainText
     *       plain text
     * @return input with html, body and head tag
     */
    public static Element toHtmlByPlain(String plainText) {
        Element html = new Element("html");
        Element head = new Element("head");
        Element body = new Element("body").text(plainText);
        return html.prependChild(body).prependChild(head);
    }
}

Related

  1. text(Element e)
  2. text(Element element)
  3. textOf(final Element el)
  4. toElement(String html)
  5. toHtmlByHtml(String html)