Example usage for org.jsoup.nodes Document insertChildren

List of usage examples for org.jsoup.nodes Document insertChildren

Introduction

In this page you can find the example usage for org.jsoup.nodes Document insertChildren.

Prototype

public Element insertChildren(int index, Collection<? extends Node> children) 

Source Link

Document

Inserts the given child nodes into this element at the specified index.

Usage

From source file:org.jboss.tools.windup.ui.internal.issues.IssueDetailsView.java

public static void addPrism(Document doc) {
    try {//from w  w w  .j  a  v a 2s.  co m
        Bundle bundle = WindupUIPlugin.getDefault().getBundle();
        Elements codeElements = doc.getElementsByTag("code");
        codeElements.forEach(element -> {
            Set<String> classNames = element.classNames();
            Set<String> newNames = Sets.newHashSet();
            classNames.forEach(className -> {
                // prismjs requires prefix, i'm not sure about another/easier workaround.
                newNames.add("language-" + className);
            });
            element.classNames(newNames);
        });

        DocumentType type = new DocumentType("html", "", "", "");
        doc.insertChildren(0, Lists.newArrayList(type));

        Element head = doc.head();
        Element css = doc.createElement("link");

        URL fileURL = FileLocator.find(bundle, new Path("html/prism.css"), null);
        String srcPath = FileLocator.resolve(fileURL).getPath();

        css.attr("href", srcPath);
        css.attr("rel", "stylesheet");
        head.appendChild(css);

        Element body = doc.body();
        Element script = doc.createElement("script");

        fileURL = FileLocator.find(bundle, new Path("html/prism.js"), null);
        srcPath = FileLocator.resolve(fileURL).getPath();

        script.attr("src", srcPath);
        body.appendChild(script);
    } catch (Exception e) {
        WindupUIPlugin.log(e);
    }
}