Exemplo n.º 1
0
  private void adjustLevel(BlockType type, String typeSpec, int level) {
    for (ListState previousState = listState.peek();
        level != previousState.level || previousState.type != type;
        previousState = listState.peek()) {

      if (level > previousState.level) {
        if (!previousState.openItem) {
          builder.beginBlock(BlockType.LIST_ITEM, new Attributes());
          previousState.openItem = true;
        }

        Attributes blockAttributes = new Attributes();
        computeAttributes(blockAttributes, type, typeSpec);

        listState.push(new ListState(previousState.level + 1, type));
        builder.beginBlock(type, blockAttributes);
      } else {
        closeOne();
        if (listState.isEmpty()) {
          Attributes blockAttributes = new Attributes();
          computeAttributes(blockAttributes, type, typeSpec);

          listState.push(new ListState(1, type));
          builder.beginBlock(type, blockAttributes);
        }
      }
    }
  }
Exemplo n.º 2
0
  @Override
  public int processLineContent(String line, int offset) {
    boolean continuation = false;
    if (blockLineCount == 0) {
      listState = new Stack<>();
      Attributes attributes = new Attributes();
      String listSpec = matcher.group(1);
      int level = calculateLevel(listSpec);
      String typeSpec = matcher.group(2);
      BlockType type = calculateType(typeSpec);

      computeAttributes(attributes, type, typeSpec);

      // 0-offset matches may start with the "*** " prefix.
      offset = matcher.start(3);

      listState.push(new ListState(1, type));
      builder.beginBlock(type, attributes);

      adjustLevel(type, listSpec, level);
    } else {
      Matcher matcher = startPattern.matcher(line);
      if (!matcher.matches()) {
        // FIXME: continuations not yet implemented
        matcher = continuationPattern.matcher(line);
        if (listState.isEmpty() || !matcher.matches()) {
          setClosed(true);
          return 0;
        } else {
          continuation = true;
          offset = matcher.start(1) - 1; // use -1 to get one whitespace character
        }
      } else {
        String listSpec = matcher.group(1);
        int level = calculateLevel(listSpec);
        String typeSpec = matcher.group(2);

        BlockType type = calculateType(typeSpec);
        offset = matcher.start(3);

        adjustLevel(type, typeSpec, level);
      }
    }
    ++blockLineCount;

    ListState listState = this.listState.peek();
    if (!continuation && listState.openItem) {
      builder.endBlock();
      listState.openItem = false;
    }
    if (!listState.openItem) {
      listState.openItem = true;
      builder.beginBlock(BlockType.LIST_ITEM, new Attributes());
    }

    markupLanguage.emitMarkupLine(getParser(), state, line, offset);

    return -1;
  }