Пример #1
0
 private boolean inlinable(final Element element) {
   // returns true if the specified element should be inlined
   final StartTagType startTagType = element.getStartTag().getStartTagType();
   if (startTagType == StartTagType.DOCTYPE_DECLARATION) return false;
   if (startTagType != StartTagType.NORMAL) return true;
   // element is a normal type
   final String elementName = element.getName();
   if (elementName == HTMLElementName.SCRIPT) return !indentScriptElements;
   if (removeLineBreaks && !HTMLElements.getElementNames().contains(elementName))
     return true; // inline non-HTML elements if removing line breaks
   if (!HTMLElements.getInlineLevelElementNames().contains(elementName)) return false;
   // element is inline type
   if (removeLineBreaks) return true;
   return containsOnlyInlineLevelChildElements(
       element); // only inline if it doesn't illegally contain non-inline elements
 }
Пример #2
0
 private boolean containsOnlyInlineLevelChildElements(final Element element) {
   // returns true if the element contains only inline-level elements except for SCRIPT elements.
   final Collection childElements = element.getChildElements();
   if (childElements.isEmpty()) return true;
   for (final Iterator i = childElements.iterator(); i.hasNext(); ) {
     final Element childElement = (Element) i.next();
     final String elementName = childElement.getName();
     if (elementName == HTMLElementName.SCRIPT
         || !HTMLElements.getInlineLevelElementNames().contains(elementName)) return false;
     if (!containsOnlyInlineLevelChildElements(childElement)) return false;
   }
   return true;
 }