public static String makeHtmlValid()

in maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/GeneratorUtils.java [231:267]


    public static String makeHtmlValid(String description) {

        if (description == null || description.isEmpty()) {
            return "";
        }

        String commentCleaned = decodeJavadocTags(description);

        // Using jTidy to clean comment
        Tidy tidy = new Tidy();
        tidy.setDocType("loose");
        tidy.setXHTML(true);
        tidy.setXmlOut(true);
        tidy.setInputEncoding("UTF-8");
        tidy.setOutputEncoding("UTF-8");
        tidy.setMakeClean(true);
        tidy.setNumEntities(true);
        tidy.setQuoteNbsp(false);
        tidy.setQuiet(true);
        tidy.setShowWarnings(true);

        ByteArrayOutputStream out = new ByteArrayOutputStream(commentCleaned.length() + 256);
        tidy.parse(new ByteArrayInputStream(commentCleaned.getBytes(StandardCharsets.UTF_8)), out);
        commentCleaned = new String(out.toByteArray(), StandardCharsets.UTF_8);

        if (commentCleaned == null || commentCleaned.isEmpty()) {
            return "";
        }

        // strip the header/body stuff
        String ls = System.getProperty("line.separator");
        int startPos = commentCleaned.indexOf("<body>" + ls) + 6 + ls.length();
        int endPos = commentCleaned.indexOf(ls + "</body>");
        commentCleaned = commentCleaned.substring(startPos, endPos);

        return commentCleaned;
    }