Here you can find the source of plainToHtml(String plain)
public static String plainToHtml(String plain)
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayInputStream; import javax.swing.text.DefaultEditorKit; import javax.swing.text.Document; public class Main { public static String plainToHtml(String plain) { DefaultEditorKit plainParser = new DefaultEditorKit(); Document document = plainParser.createDefaultDocument(); try {//from ww w .ja va 2 s .c o m plainParser.read(new ByteArrayInputStream(plain.getBytes()), document, 0); String html = document.getText(0, document.getLength()); return html; } catch (Exception e) { throw new RuntimeException("Error converting plain text to HTML", e); } } }