Java Code Examples for org.commonmark.internal.util.Parsing#skip()
The following examples show how to use
org.commonmark.internal.util.Parsing#skip() .
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: JLatexMathBlockParser.java From Markwon with Apache License 2.0 | 6 votes |
@Override public BlockContinue tryContinue(ParserState parserState) { final int nextNonSpaceIndex = parserState.getNextNonSpaceIndex(); final CharSequence line = parserState.getLine(); final int length = line.length(); // check for closing if (parserState.getIndent() < Parsing.CODE_BLOCK_INDENT) { if (consume(DOLLAR, line, nextNonSpaceIndex, length) == signs) { // okay, we have our number of signs // let's consume spaces until the end if (Parsing.skip(SPACE, line, nextNonSpaceIndex + signs, length) == length) { return BlockContinue.finished(); } } } return BlockContinue.atIndex(parserState.getIndex()); }
Example 2
Source File: JLatexMathBlockParser.java From Markwon with Apache License 2.0 | 5 votes |
@Override public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockParser) { // let's define the spec: // * 0-3 spaces before are allowed (Parsing.CODE_BLOCK_INDENT = 4) // * 2+ subsequent `$` signs // * any optional amount of spaces // * new line // * block is closed when the same amount of opening signs is met final int indent = state.getIndent(); // check if it's an indented code block if (indent >= Parsing.CODE_BLOCK_INDENT) { return BlockStart.none(); } final int nextNonSpaceIndex = state.getNextNonSpaceIndex(); final CharSequence line = state.getLine(); final int length = line.length(); final int signs = consume(DOLLAR, line, nextNonSpaceIndex, length); // 2 is minimum if (signs < 2) { return BlockStart.none(); } // consume spaces until the end of the line, if any other content is found -> NONE if (Parsing.skip(SPACE, line, nextNonSpaceIndex + signs, length) != length) { return BlockStart.none(); } return BlockStart.of(new JLatexMathBlockParser(signs)) .atIndex(length + 1); }
Example 3
Source File: HeadingParser.java From commonmark-java with BSD 2-Clause "Simplified" License | 5 votes |
private static HeadingParser getAtxHeading(CharSequence line, int index) { int level = Parsing.skip('#', line, index, line.length()) - index; if (level == 0 || level > 6) { return null; } int start = index + level; if (start >= line.length()) { // End of line after markers is an empty heading return new HeadingParser(level, ""); } char next = line.charAt(start); if (!(next == ' ' || next == '\t')) { return null; } int beforeSpace = Parsing.skipSpaceTabBackwards(line, line.length() - 1, start); int beforeHash = Parsing.skipBackwards('#', line, beforeSpace, start); int beforeTrailer = Parsing.skipSpaceTabBackwards(line, beforeHash, start); if (beforeTrailer != beforeHash) { return new HeadingParser(level, line.subSequence(start, beforeTrailer + 1).toString()); } else { return new HeadingParser(level, line.subSequence(start, beforeSpace + 1).toString()); } }
Example 4
Source File: FencedCodeBlockParser.java From commonmark-java with BSD 2-Clause "Simplified" License | 5 votes |
private boolean isClosing(CharSequence line, int index) { char fenceChar = block.getFenceChar(); int fenceLength = block.getFenceLength(); int fences = Parsing.skip(fenceChar, line, index, line.length()) - index; if (fences < fenceLength) { return false; } // spec: The closing code fence [...] may be followed only by spaces, which are ignored. int after = Parsing.skipSpaceTab(line, index + fences, line.length()); return after == line.length(); }
Example 5
Source File: HeadingParser.java From commonmark-java with BSD 2-Clause "Simplified" License | 4 votes |
private static boolean isSetextHeadingRest(CharSequence line, int index, char marker) { int afterMarker = Parsing.skip(marker, line, index, line.length()); int afterSpace = Parsing.skipSpaceTab(line, afterMarker, line.length()); return afterSpace >= line.length(); }