Java Code Examples for org.commonmark.internal.util.Parsing#columnsToNextTabStop()

The following examples show how to use org.commonmark.internal.util.Parsing#columnsToNextTabStop() . 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: DocumentParser.java    From 1Rramp-Android with MIT License 6 votes vote down vote up
/**
 * Add line content to the active block parser. We assume it can accept lines -- that check should be done before
 * calling this.
 */
private void addLine() {
    CharSequence content;
    if (columnIsInTab) {
        // Our column is in a partially consumed tab. Expand the remaining columns (to the next tab stop) to spaces.
        int afterTab = index + 1;
        CharSequence rest = line.subSequence(afterTab, line.length());
        int spaces = Parsing.columnsToNextTabStop(column);
        StringBuilder sb = new StringBuilder(spaces + rest.length());
        for (int i = 0; i < spaces; i++) {
            sb.append(' ');
        }
        sb.append(rest);
        content = sb.toString();
    } else {
        content = line.subSequence(index, line.length());
    }
    getActiveBlockParser().addLine(content);
}
 
Example 2
Source File: DocumentParser.java    From commonmark-java with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Add line content to the active block parser. We assume it can accept lines -- that check should be done before
 * calling this.
 */
private void addLine() {
    CharSequence content;
    if (columnIsInTab) {
        // Our column is in a partially consumed tab. Expand the remaining columns (to the next tab stop) to spaces.
        int afterTab = index + 1;
        CharSequence rest = line.subSequence(afterTab, line.length());
        int spaces = Parsing.columnsToNextTabStop(column);
        StringBuilder sb = new StringBuilder(spaces + rest.length());
        for (int i = 0; i < spaces; i++) {
            sb.append(' ');
        }
        sb.append(rest);
        content = sb.toString();
    } else {
        content = line.subSequence(index, line.length());
    }
    getActiveBlockParser().addLine(content);
}
 
Example 3
Source File: DocumentParser.java    From 1Rramp-Android with MIT License 5 votes vote down vote up
private void advance() {
    char c = line.charAt(index);
    if (c == '\t') {
        index++;
        column += Parsing.columnsToNextTabStop(column);
    } else {
        index++;
        column++;
    }
}
 
Example 4
Source File: DocumentParser.java    From commonmark-java with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void advance() {
    char c = line.charAt(index);
    if (c == '\t') {
        index++;
        column += Parsing.columnsToNextTabStop(column);
    } else {
        index++;
        column++;
    }
}
 
Example 5
Source File: ListBlockParser.java    From 1Rramp-Android with MIT License 4 votes vote down vote up
/**
 * Parse a list marker and return data on the marker or null.
 */
private static ListData parseListMarker(CharSequence line, final int markerIndex, final int markerColumn,
                                        final boolean inParagraph) {
    CharSequence rest = line.subSequence(markerIndex, line.length());
    Matcher matcher = MARKER.matcher(rest);
    if (!matcher.find()) {
        return null;
    }

    ListBlock listBlock = createListBlock(matcher);

    int markerLength = matcher.end() - matcher.start();
    int indexAfterMarker = markerIndex + markerLength;
    // marker doesn't include tabs, so counting them as columns directly is ok
    int columnAfterMarker = markerColumn + markerLength;
    // the column within the line where the content starts
    int contentColumn = columnAfterMarker;

    // See at which column the content starts if there is content
    boolean hasContent = false;
    for (int i = indexAfterMarker; i < line.length(); i++) {
        char c = line.charAt(i);
        if (c == '\t') {
            contentColumn += Parsing.columnsToNextTabStop(contentColumn);
        } else if (c == ' ') {
            contentColumn++;
        } else {
            hasContent = true;
            break;
        }
    }

    if (inParagraph) {
        // If the list item is ordered, the start number must be 1 to interrupt a paragraph.
        if (listBlock instanceof OrderedList && ((OrderedList) listBlock).getStartNumber() != 1) {
            return null;
        }
        // Empty list item can not interrupt a paragraph.
        if (!hasContent) {
            return null;
        }
    }

    if (!hasContent || (contentColumn - columnAfterMarker) > Parsing.CODE_BLOCK_INDENT) {
        // If this line is blank or has a code block, default to 1 space after marker
        contentColumn = columnAfterMarker + 1;
    }

    return new ListData(listBlock, contentColumn);
}
 
Example 6
Source File: ListBlockParser.java    From commonmark-java with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Parse a list marker and return data on the marker or null.
 */
private static ListData parseList(CharSequence line, final int markerIndex, final int markerColumn,
                                  final boolean inParagraph) {
    ListMarkerData listMarker = parseListMarker(line, markerIndex);
    if (listMarker == null) {
        return null;
    }
    ListBlock listBlock = listMarker.listBlock;

    int indexAfterMarker = listMarker.indexAfterMarker;
    int markerLength = indexAfterMarker - markerIndex;
    // marker doesn't include tabs, so counting them as columns directly is ok
    int columnAfterMarker = markerColumn + markerLength;
    // the column within the line where the content starts
    int contentColumn = columnAfterMarker;

    // See at which column the content starts if there is content
    boolean hasContent = false;
    int length = line.length();
    for (int i = indexAfterMarker; i < length; i++) {
        char c = line.charAt(i);
        if (c == '\t') {
            contentColumn += Parsing.columnsToNextTabStop(contentColumn);
        } else if (c == ' ') {
            contentColumn++;
        } else {
            hasContent = true;
            break;
        }
    }

    if (inParagraph) {
        // If the list item is ordered, the start number must be 1 to interrupt a paragraph.
        if (listBlock instanceof OrderedList && ((OrderedList) listBlock).getStartNumber() != 1) {
            return null;
        }
        // Empty list item can not interrupt a paragraph.
        if (!hasContent) {
            return null;
        }
    }

    if (!hasContent || (contentColumn - columnAfterMarker) > Parsing.CODE_BLOCK_INDENT) {
        // If this line is blank or has a code block, default to 1 space after marker
        contentColumn = columnAfterMarker + 1;
    }

    return new ListData(listBlock, contentColumn);
}