Menu

Removing inline CSS

2018-03-30
2018-04-04
  • Ritesh Bhambhani

    Hello,
    I was wondering if I can use Jericho for removing all inline CSS. The need is that if there is a HTML that comes with a tag with embeded styles then before sending it out to any other application which may want to apply its own styles remove all inline style.
    Ex:

    Ritesh Bhambhani

    Output:
    Ritesh Bhambhani

     
  • Martin Jericho

    Martin Jericho - 2018-04-01

    Your example code didn't make it into the post, but try something like this:

    OutputDocument outputDocument=new OutputDocument(source);
    outputDocument.remove(source.getAllElements(HTMLElementName.STYLE));
    for (StartTag startTag : source.getAllStartTags("style",null)) {
        // iterate all tags with a style attribute
        outputDocument.remove(startTag.getAttributes().get("style"));
    }
    String newHTML=outputDocument.toString();
    
     
  • Ritesh Bhambhani

    Thanks so much

     

Log in to post a comment.