Java Code Examples for org.commonmark.parser.InlineParser#parse()

The following examples show how to use org.commonmark.parser.InlineParser#parse() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskListBlockParser.java    From Markwon with Apache License 2.0 6 votes vote down vote up
@Override
public void parseInlines(InlineParser inlineParser) {

    Matcher matcher;

    TaskListItem listItem;

    for (Item item : items) {
        matcher = PATTERN.matcher(item.line);
        if (!matcher.matches()) {
            continue;
        }
        listItem = new TaskListItem()
                .done(isDone(matcher.group(2)))
                .indent(item.indent / 2);
        inlineParser.parse(matcher.group(3), listItem);
        block.appendChild(listItem);
    }
}
 
Example 2
Source File: TableBlockParser.java    From js-dossier with Apache License 2.0 6 votes vote down vote up
@Override
public void parseInlines(InlineParser inlineParser) {
  Node headNode = new TableHeadNode();
  block.appendChild(headNode);
  headNode.appendChild(parseRow(headerRow.toString(), inlineParser));

  // The first row of data is always the column alignments, which we've already parsed.
  Node bodyNode = new TableBodyNode();
  block.appendChild(bodyNode);
  String caption = null;
  for (CharSequence line : Iterables.skip(rowData, 1)) {
    Matcher captionMatcher = CAPTION_LINE.matcher(line);
    if (captionMatcher.matches()) {
      caption = captionMatcher.group("content").trim();
    } else {
      TableRowNode row = parseRow(line.toString(), inlineParser);
      bodyNode.appendChild(row);
    }
  }

  if (!isNullOrEmpty(caption)) {
    TableCaptionNode captionNode = new TableCaptionNode();
    headNode.insertBefore(captionNode);
    inlineParser.parse(caption.trim(), captionNode);
  }
}
 
Example 3
Source File: ParagraphParser.java    From commonmark-java with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void parseInlines(InlineParser inlineParser) {
    CharSequence content = linkReferenceDefinitionParser.getParagraphContent();
    if (content.length() > 0) {
        inlineParser.parse(content.toString(), block);
    }
}
 
Example 4
Source File: TableBlockParser.java    From commonmark-java with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private TableCell parseCell(String cell, int column, InlineParser inlineParser) {
    TableCell tableCell = new TableCell();

    if (column < columns.size()) {
        tableCell.setAlignment(columns.get(column));
    }

    inlineParser.parse(cell.trim(), tableCell);

    return tableCell;
}
 
Example 5
Source File: HeadingParser.java    From 1Rramp-Android with MIT License 4 votes vote down vote up
@Override
public void parseInlines(InlineParser inlineParser) {
    inlineParser.parse(content, block);
}
 
Example 6
Source File: ParagraphParser.java    From 1Rramp-Android with MIT License 4 votes vote down vote up
@Override
public void parseInlines(InlineParser inlineParser) {
    if (content != null) {
        inlineParser.parse(content.getString(), block);
    }
}
 
Example 7
Source File: HeadingParser.java    From commonmark-java with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void parseInlines(InlineParser inlineParser) {
    inlineParser.parse(content, block);
}
 
Example 8
Source File: TableBlockParser.java    From js-dossier with Apache License 2.0 4 votes vote down vote up
private TableRowNode parseRow(String rowStr, InlineParser inlineParser) {
  rowStr = rowStr.trim();
  if (rowStr.startsWith("|")) {
    rowStr = rowStr.substring(1);
  }

  TableRowNode row = new TableRowNode();

  boolean isEscaped = false;
  int currentColumn = 0;
  CharBuffer data = CharBuffer.wrap(rowStr);
  for (int index = 0; data.hasRemaining(); index++) {
    if (isEscaped) {
      isEscaped = false;
      continue;
    }

    char c = data.charAt(index);
    if (c == '\\') {
      isEscaped = true;
      continue;
    }

    if (c == '|' || (index + 1) >= data.remaining()) {
      int end = c == '|' ? index : index + 1;
      String content = data.subSequence(0, end).toString();
      data.position(data.position() + end);

      int colSpan = 0;
      while (data.hasRemaining() && data.charAt(0) == '|') {
        colSpan++;
        data.position(data.position() + 1);
      }
      index = -1; // Account for post-forloop increment.
      Alignment alignment =
          currentColumn < columns.size() ? columns.get(currentColumn) : Alignment.NONE;
      currentColumn += colSpan;

      TableCellNode cell = new TableCellNode(colSpan, alignment);
      inlineParser.parse(content.trim(), cell);
      row.appendChild(cell);
    }
  }

  return row;
}