Package info.bliki.htmlcleaner

Examples of info.bliki.htmlcleaner.TagToken


              + ':' + imageName);
        }
      }
      imageSrc = imageSrc.replace("${image}", imageName);
      String type = imageFormat.getType();
      TagToken tag = null;
      if ("thumb".equals(type) || "frame".equals(type)) {
        if (fTagStack.size() > 0) {
          tag = peekNode();
        }
        reduceTokenStack(Configuration.HTML_DIV_OPEN);
View Full Code Here


                if (fSource[fCurrentPosition] != '/') {
                  // opening HTML tag
                  WikiTagNode tagNode = parseTag(fCurrentPosition);
                  if (tagNode != null) {
                    String tagName = tagNode.getTagName();
                    TagToken tag = fWikiModel.getTokenMap().get(tagName);
                    if ((tag != null) && !(tag instanceof HTMLBlockTag)) {
                      tag = (TagToken) tag.clone();

                      if (tag instanceof TagNode) {
                        TagNode node = (TagNode) tag;
                        List<NodeAttribute> attributes = tagNode.getAttributesEx();
                        Attribute attr;
                        for (int i = 1; i < attributes.size(); i++) {
                          attr = attributes.get(i);
                          node.addAttribute(attr.getName(), attr.getValue(), true);
                        }
                      }
                      if (tag instanceof HTMLTag) {
                        // ((HTMLTag) tag).setTemplate(isTemplate());
                      }

                      createContentToken(1);

                      fCurrentPosition = fScannerPosition;

                      String allowedParents = tag.getParents();
                      if (allowedParents != null) {
                        reduceTokenStack(tag);
                      }
                      createTag(tag, tagNode, tagNode.getEndPosition());
                      return TokenIgnore;

                    }
                    break;
                  }
                } else {
                  // closing HTML tag
                  WikiTagNode tagNode = parseTag(++fCurrentPosition);
                  if (tagNode != null) {
                    String tagName = tagNode.getTagName();
                    TagToken tag = fWikiModel.getTokenMap().get(tagName);
                    if ((tag != null) && !(tag instanceof HTMLBlockTag)) {
                      createContentToken(2);
                      fCurrentPosition = fScannerPosition;

                      if (fWikiModel.stackSize() > 0) {
                        TagToken topToken = fWikiModel.peekNode();
                        if (topToken.getName().equals(tag.getName())) {
                          fWikiModel.popNode();
                          return TokenIgnore;
                        } else {
                          if (tag.isReduceTokenStack()) {
                            reduceStackUntilToken(tag);
View Full Code Here

  /**
   * Reduce the current token stack until the given nodes name is at the top of
   * the stack. Useful for closing HTML tags.
   */
  protected void reduceStackUntilToken(TagToken node) {
    TagToken tag;
    int index = -1;
    String allowedParents = node.getParents();
    while (fWikiModel.stackSize() > 0) {
      tag = fWikiModel.peekNode();
      if (node.getName().equals(tag.getName())) {
        fWikiModel.popNode();
        break;
      }
      if (allowedParents == null) {
        fWikiModel.popNode();
      } else {
        index = allowedParents.indexOf("|" + tag.getName() + "|");
        if (index < 0) {
          fWikiModel.popNode();
        } else {
          break;
        }
View Full Code Here

   * stack
   */
  public void reduceTokenStack(TagToken node) {
    String allowedParents = node.getParents();
    if (allowedParents != null) {
      TagToken tag;
      int index = -1;

      while (stackSize() > 0) {
        tag = peekNode();
        index = allowedParents.indexOf("|" + tag.getName() + "|");
        if (index < 0) {
          popNode();
          if (tag.getName().equals(node.getName())) {
            // for wrong nested HTML tags like <table> <tr><td>number
            // 1<tr><td>number 2</table>
            break;
          }
        } else {
View Full Code Here

    if (isStartOfLine()) {
      createContentToken(fWhiteStart, fWhiteStartPosition, 1);

      int startHeadPosition = fCurrentPosition;
      if (readUntilEOL()) {
        TagToken dl = new DlTag();
        TagToken dt = new DtTag();
        reduceTokenStack(dl);
        String head = fStringSource.substring(startHeadPosition, fCurrentPosition);
        int index = head.indexOf(" : ");
        if (index > 0) {
          fWikiModel.pushNode(dl);
View Full Code Here

  }

  private void reduceTokenStackBoldItalic() {
    boolean found = false;
    while (fWikiModel.stackSize() > 0) {
      TagToken token = fWikiModel.peekNode();//
      if (token.equals(BOLD) || token.equals(ITALIC) || token.equals(BOLDITALIC)) {
        if (fWhiteStart) {
          found = true;
          createContentToken(fWhiteStart, fWhiteStartPosition, 1);
        }
        fWikiModel.popNode();
View Full Code Here

   * stack
   */
  private void reduceTokenStack(TagToken node) {
    String allowedParents = node.getParents();
    if (allowedParents != null) {
      TagToken tag;
      int index = -1;

      while (fWikiModel.stackSize() > 0) {
        tag = fWikiModel.peekNode();
        index = allowedParents.indexOf("|" + tag.getName() + "|");
        if (index < 0) {
          fWikiModel.popNode();
          if (tag.getName().equals(node.getName())) {
            // for wrong nested HTML tags like <table> <tr><td>number
            // 1<tr><td>number 2</table>
            break;
          }
        } else {
View Full Code Here

  /**
   * Reduce the current token stack until the given nodes name is at the top of
   * the stack. Useful for closing HTML tags.
   */
  private void reduceStackUntilToken(TagToken node) {
    TagToken tag;
    int index = -1;
    String allowedParents = node.getParents();
    while (fWikiModel.stackSize() > 0) {
      tag = fWikiModel.peekNode();
      if (node.getName().equals(tag.getName())) {
        fWikiModel.popNode();
        break;
      }
      if (allowedParents == null) {
        fWikiModel.popNode();
      } else {
        index = allowedParents.indexOf("|" + tag.getName() + "|");
        if (index < 0) {
          fWikiModel.popNode();
        } else {
          break;
        }
View Full Code Here

          } else {
            if (!isEmptyLine(1)) {
              if (fWikiModel.stackSize() == 0) {
                addParagraph();
              } else {
                TagToken tag = fWikiModel.peekNode();
                if (tag instanceof WPPreTag) {
                  addParagraph();
                  // } else if (tag instanceof PTag) {
                  // createContentToken(fWhiteStart, fWhiteStartPosition, 2);
                  // reduceTokenStack(Configuration.HTML_PARAGRAPH_OPEN);
                } else {
                  String allowedParents = Configuration.HTML_PARAGRAPH_OPEN.getParents();
                  if (allowedParents != null) {

                    int index = -1;
                    index = allowedParents.indexOf("|" + tag.getName() + "|");
                    if (index >= 0) {
                      addParagraph();
                    }
                  }
                }
              }
            }
          }
        }

        // ---------Identify the next token-------------
        switch (fCurrentCharacter) {
        case '~':
          if (handleSourroundingTags2('~', "del", Configuration.HTML_DEL_OPEN)) {
            continue;
          }
          break;
        // if (fSource[fCurrentPosition] == '~') {
        // ++fCurrentPosition;
        // createContentToken(fWhiteStart, fWhiteStartPosition, 2);
        // if (fWikiModel.stackSize() > 0 &&
        // fWikiModel.peekNode().equals(Configuration.HTML_DEL_OPEN)) {
        // fWikiModel.popNode();
        // } else {
        // fWikiModel.pushNode(new WPTag("del"));
        // }
        // continue;
        // }
        // break;
        case '_':
          if (handleSourroundingTags2('_', "u", Configuration.HTML_U_OPEN)) {
            continue;
          }
          break;
        case ',':
          if (handleSourroundingTags2(',', "sub", Configuration.HTML_SUB_OPEN)) {
            continue;
          }
          break;
        case '^':
          if (handleSourroundingTags1("sup", Configuration.HTML_SUP_OPEN)) {
            continue;
          }
          break;
        case '{':
          if (fSource[fCurrentPosition++] == '{' && fSource[fCurrentPosition++] == '{') {
            int startPosition = fCurrentPosition;
            if (fSource[fCurrentPosition] == '\n') {
              int preStartPosition = startPosition + 1;
              if (readUntil("\n}}}")) {
                TagToken preTag = new HTMLTag("pre");
                createContentTag(startPosition, fCurrentPosition - 3, preTag);
                continue;
              }
            }
            if (readUntil("}}}")) {
              TagToken ttTag = new HTMLTag("tt");
              createContentTag(startPosition, fCurrentPosition - 3, ttTag);
              continue;
            }
          }
          break;
        case '`':
          int startPosition = fCurrentPosition;
          if (readUntil("`")) {
            createContentTag(startPosition, fCurrentPosition - 1, new HTMLTag("tt"));
            continue;
          }
          break;
        case '[':
          if (parseWikiLink()) {
            continue;
          }
          break;
        case '\'':
          if (getNextChar('\'')) {
            if (getNextChar('\'')) {
              if (getNextChar('\'')) {
                if (getNextChar('\'')) {
                  createContentToken(fWhiteStart, fWhiteStartPosition, 5);
                  return TokenBOLDITALIC;
                }
                fCurrentPosition -= 1;
                fWhiteStart = true;
                createContentToken(fWhiteStart, fWhiteStartPosition, 3);
                return TokenBOLD;
              }
              createContentToken(fWhiteStart, fWhiteStartPosition, 3);
              return TokenBOLD;
            }
            createContentToken(fWhiteStart, fWhiteStartPosition, 2);
            return TokenITALIC;
          }
          break;
        case 'A':
        case 'B':
        case 'C':
        case 'D':
        case 'E':
        case 'G':
        case 'J':
        case 'K':
        case 'L':
        case 'N':
        case 'O':
        case 'P':
        case 'Q':
        case 'R':
        case 'S':
        case 'T':
        case 'U':
        case 'V':
        case 'W':
        case 'X':
        case 'Y':
        case 'Z':
          if (parseCamelCaseNames(fCurrentCharacter)) {
            continue;
          }
          break;
        case 'f': // ftp://
        case 'F':
          if (parseFTPLinks()) {
            continue;
          }
          if (parseCamelCaseNames(fCurrentCharacter)) {
            continue;
          }
          break;
        case 'h': // http(s)://
        case 'H':
          if (parseHTTPLinks()) {
            continue;
          }
          if (parseCamelCaseNames(fCurrentCharacter)) {
            continue;
          }
          break;
        case 'i': // "ISBN ..."
        case 'I':
          if (parseISBNLinks()) {
            continue;
          }
          if (parseCamelCaseNames(fCurrentCharacter)) {
            continue;
          }
          break;
        case 'm': // mailto:
        case 'M':
          if (parseMailtoLinks()) {
            continue;
          }
          if (parseCamelCaseNames(fCurrentCharacter)) {
            continue;
          }
          break;
        case '<':
          if (fHtmlCodes) {
            int htmlStartPosition = fCurrentPosition;
            // HTML tags are allowed
            try {
              switch (fSource[fCurrentPosition]) {
              case '!': // <!-- HTML comment -->
                if (parseHTMLCommentTags()) {
                  continue;
                }
                break;
              default:

                if (fSource[fCurrentPosition] != '/') {
                  // opening HTML tag
                  WikiTagNode tagNode = parseTag(fCurrentPosition);
                  if (tagNode != null) {
                    String tagName = tagNode.getTagName();
                    TagToken tag = fWikiModel.getTokenMap().get(tagName);
                    if (tag != null) {
                      tag = (TagToken) tag.clone();

                      if (tag instanceof TagNode) {
                        TagNode node = (TagNode) tag;
                        List<NodeAttribute> attributes = tagNode.getAttributesEx();
                        Attribute attr;
                        for (int i = 1; i < attributes.size(); i++) {
                          attr = attributes.get(i);
                          node.addAttribute(attr.getName(), attr.getValue(), true);
                        }
                      }
                      if (tag instanceof HTMLTag) {
                        ((HTMLTag) tag).setTemplate(isTemplate());
                      }

                      createContentToken(fWhiteStart, fWhiteStartPosition, 1);

                      fCurrentPosition = fScannerPosition;

                      String allowedParents = tag.getParents();
                      if (allowedParents != null) {
                        reduceTokenStack(tag);
                      }
                      createTag(tag, tagNode, tagNode.getEndPosition());
                      return TokenIgnore;

                    }
                    break;
                  }
                } else {
                  // closing HTML tag
                  WikiTagNode tagNode = parseTag(++fCurrentPosition);
                  if (tagNode != null) {
                    String tagName = tagNode.getTagName();
                    TagToken tag = fWikiModel.getTokenMap().get(tagName);
                    if (tag != null) {
                      createContentToken(fWhiteStart, fWhiteStartPosition, 2);
                      fCurrentPosition = fScannerPosition;

                      if (fWikiModel.stackSize() > 0) {
                        TagToken topToken = fWikiModel.peekNode();
                        if (topToken.getName().equals(tag.getName())) {
                          fWikiModel.popNode();
                          return TokenIgnore;
                        } else {
                          if (tag.isReduceTokenStack()) {
                            reduceStackUntilToken(tag);
View Full Code Here

    if (isStartOfLine()) {
      createContentToken(fWhiteStart, fWhiteStartPosition, 1);

      int startHeadPosition = fCurrentPosition;
      if (readUntilEOL()) {
        TagToken dl = new DlTag();
        TagToken dt = new DtTag();
        reduceTokenStack(dl);
        String head = new String(fSource, startHeadPosition, fCurrentPosition - startHeadPosition);
        int index = head.indexOf(" : ");
        if (index > 0) {
          fWikiModel.pushNode(dl);
View Full Code Here

TOP

Related Classes of info.bliki.htmlcleaner.TagToken

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.