String (@NotNull String text) { int htmlIndex = 6 + text.indexOf("<html>"); if (htmlIndex < 6) { return text.replaceAll("\n", "<br>"); } int htmlCloseIndex = text.indexOf("</html>", htmlIndex); if (htmlCloseIndex < 0) { htmlCloseIndex = text.length(); } int bodyIndex = 6 + text.indexOf("<body>", htmlIndex); if (bodyIndex < 6) { return text.substring(htmlIndex, htmlCloseIndex); } int bodyCloseIndex = text.indexOf("</body>", bodyIndex); if (bodyCloseIndex < 0) { bodyCloseIndex = text.length(); } return text.substring(bodyIndex, Math.min(bodyCloseIndex, htmlCloseIndex)); }