private void prepArticle ( Element articleContent ) { cleanStyles ( articleContent ) ; killBreaks ( articleContent ) ; /* Clean out junk from the article content */ clean ( articleContent , "form" ) ; clean ( articleContent , "object" ) ; clean ( articleContent , "h1" ) ; /** * If there is only one h2, they are probably using it as a header and * not a subheader, so remove it since we already have a header. */ if ( getElementsByTag ( articleContent , "h2" ) . size ( ) == 1 ) { clean ( articleContent , "h2" ) ; } clean ( articleContent , "iframe" ) ; cleanHeaders ( articleContent ) ; /* * Do these last as the previous stuff may have removed junk that will * affect these */ cleanConditionally ( articleContent , "table" ) ; cleanConditionally ( articleContent , "ul" ) ; cleanConditionally ( articleContent , "div" ) ; /* Remove extra paragraphs */ Elements articleParagraphs = getElementsByTag ( articleContent , "p" ) ; for ( Element articleParagraph : articleParagraphs ) { int imgCount = getElementsByTag ( articleParagraph , "img" ) . size ( ) ; int embedCount = getElementsByTag ( articleParagraph , "embed" ) . size ( ) ; int objectCount = getElementsByTag ( articleParagraph , "object" ) . size ( ) ; if ( imgCount == 0 && embedCount == 0 && objectCount == 0 && isEmpty ( getInnerText ( articleParagraph , false ) ) ) { articleParagraph . remove ( ) ; } } try { articleContent . html ( articleContent . html ( ) . replaceAll ( "(?i)<br[^>]*>\\s*<p" , "<p" ) ) ; } catch ( Exception e ) { dbg ( "Cleaning innerHTML of breaks failed. This is an IE strict-block-elements bug. Ignoring." , e ) ; } }
Prepare the article node for display . Clean out any inline styles iframes forms strip extraneous &lt ; p&gt ; tags etc .