@Override public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockParser) { CharSequence line = state.getLine(); BlockParser parentParser = matchedBlockParser.getBlockParser(); // check whether this line is the first line of whole document or not if (parentParser instanceof DocumentBlockParser && parentParser.getBlock().getFirstChild() == null && REGEX_BEGIN.matcher(line).matches()) { return BlockStart.of(new YamlFrontMatterBlockParser()).atIndex(state.getNextNonSpaceIndex()); } return BlockStart.none(); } }
@Override public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockParser) { int nextNonSpace = state.getNextNonSpaceIndex(); BasedSequence line = state.getLine(); Matcher matcher; if (state.getIndent() < 4) { BasedSequence trySequence = line.subSequence(nextNonSpace, line.length()); if ((matcher = OPENING_FENCE.matcher(trySequence)).find()) { int fenceLength = matcher.group(0).length(); char fenceChar = matcher.group(0).charAt(0); FencedCodeBlockParser blockParser = new FencedCodeBlockParser(state.getProperties(), fenceChar, fenceLength, state.getIndent(), nextNonSpace); blockParser.block.setOpeningMarker(trySequence.subSequence(0, fenceLength)); return BlockStart.of(blockParser).atIndex(nextNonSpace + fenceLength); } } return BlockStart.none(); } }
@Override public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockParser) { if (state.getIndent() >= 4) { return BlockStart.none(); } BasedSequence line = state.getLine(); int nextNonSpace = state.getNextNonSpaceIndex(); BasedSequence trySequence = line.subSequence(nextNonSpace, line.length()); Matcher matcher = myParsing.TOC_BLOCK_START.matcher(line); if (matcher.matches()) { BasedSequence tocChars = state.getLineWithEOL(); BasedSequence styleChars = null; BasedSequence titleChars = null; if (matcher.start(1) != -1) { styleChars = trySequence.subSequence(matcher.start(1), matcher.end(1)); } if (matcher.start(2) != -1) { titleChars = trySequence.subSequence(matcher.start(2), matcher.end(2)); } SimTocBlockParser simTocBlockParser = new SimTocBlockParser(state.getProperties(), tocChars, styleChars, titleChars); return BlockStart.of(simTocBlockParser) .atIndex(state.getLineEndIndex() + state.getLineEolLength()) //.replaceActiveBlockParser() ; } return none(); } }
@Override public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockParser) { if (state.getIndent() >= 4) { return BlockStart.none(); } BasedSequence line = state.getLine(); int nextNonSpace = state.getNextNonSpaceIndex(); BasedSequence trySequence = line.subSequence(nextNonSpace, line.length()); Matcher matcher = myParsing.TOC_BLOCK_START.matcher(line); if (matcher.matches()) { BasedSequence tocChars = state.getLineWithEOL(); BasedSequence styleChars = null; BasedSequence titleChars = null; if (matcher.start(1) != -1) { int styleStart = matcher.start(1); int styleEnd = matcher.end(1); styleChars = trySequence.subSequence(styleStart, styleEnd); } TocBlockParser tocBlockParser = new TocBlockParser(state.getProperties(), tocChars, styleChars); return BlockStart.of(tocBlockParser) .atIndex(state.getIndex()) //.replaceActiveBlockParser() ; } return none(); } }
@Override public BlockContinue tryContinue(ParserState state) { int nextNonSpace = state.getNextNonSpaceIndex(); int newIndex = state.getIndex(); BasedSequence line = state.getLine(); Matcher matcher; boolean matches = (state.getIndent() <= 3 && nextNonSpace < line.length() && (!matchingCloser || line.charAt(nextNonSpace) == fenceChar)); if (matches) { BasedSequence trySequence = line.subSequence(nextNonSpace, line.length()); matcher = CLOSING_FENCE.matcher(trySequence); if (matcher.find()) { int foundFenceLength = matcher.group(0).length(); if (foundFenceLength >= fenceLength) { // closing fence - we're at end of line, so we can finalize now block.setClosingMarker(trySequence.subSequence(0, foundFenceLength)); return BlockContinue.finished(); } } } // skip optional spaces of fence indent int i = fenceIndent; while (i > 0 && newIndex < line.length() && line.charAt(newIndex) == ' ') { newIndex++; i--; } return BlockContinue.atIndex(newIndex); }
@Override public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockParser) { if (state.getIndent() >= 4 || matchedBlockParser.getBlockParser().isParagraphParser() && !options.relaxedStart) { return BlockStart.none(); } BasedSequence line = state.getLine(); final BasedSequence input = line.subSequence(state.getNextNonSpaceIndex(), line.length()); if (PATTERN.matcher(input).matches()) { return BlockStart.of(new ThematicBreakParser(line.subSequence(state.getIndex()))).atIndex(line.length()); } else { return BlockStart.none(); } } }
@Override public BlockContinue tryContinue(ParserState state) { if (state.getIndent() >= state.getParsing().CODE_BLOCK_INDENT) { return BlockContinue.atColumn(state.getColumn() + state.getParsing().CODE_BLOCK_INDENT); } else if (state.isBlank()) { return BlockContinue.atIndex(state.getNextNonSpaceIndex()); } else { return BlockContinue.none(); } }
@Override public BlockContinue tryContinue(ParserState state) { final int nonSpaceIndex = state.getNextNonSpaceIndex(); if (state.isBlank()) { hadBlankLine = true; return BlockContinue.atIndex(nonSpaceIndex); } else if (!hadBlankLine && options.allowLazyContinuation) { return BlockContinue.atIndex(nonSpaceIndex); } else if (state.getIndent() >= options.contentIndent) { int contentIndent = state.getColumn() + options.contentIndent; return BlockContinue.atColumn(contentIndent); } else { return BlockContinue.none(); } }
int nextNonSpace = state.getNextNonSpaceIndex(); BlockParser matched = matchedBlockParser.getBlockParser(); boolean inParagraph = matched.isParagraphParser();
@Override public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockParser) { if (state.getIndent() >= 4) { return BlockStart.none(); } BasedSequence line = state.getLine(); int nextNonSpace = state.getNextNonSpaceIndex(); BasedSequence trySequence = line.subSequence(nextNonSpace, line.length()); Matcher matcher = FOOTNOTE_DEF_PATTERN.matcher(trySequence); if (matcher.find()) { // abbreviation definition int openingStart = nextNonSpace + matcher.start(); int openingEnd = nextNonSpace + matcher.end(); BasedSequence openingMarker = line.subSequence(openingStart, openingStart + 2); BasedSequence text = line.subSequence(openingStart + 2, openingEnd - 2).trim(); BasedSequence closingMarker = line.subSequence(openingEnd - 2, openingEnd); int contentOffset = options.contentIndent; FootnoteBlockParser footnoteBlockParser = new FootnoteBlockParser(options, contentOffset); footnoteBlockParser.block.setOpeningMarker(openingMarker); footnoteBlockParser.block.setText(text); footnoteBlockParser.block.setClosingMarker(closingMarker); return BlockStart.of(footnoteBlockParser) .atIndex(openingEnd); } else { return BlockStart.none(); } } }
@Override public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockParser) { if (state.getIndent() >= 4) { return BlockStart.none(); } BasedSequence line = state.getLine(); int nextNonSpace = state.getNextNonSpaceIndex(); BasedSequence trySequence = line.subSequence(nextNonSpace, line.length()); Matcher matcher = ENUM_REF_DEF_PATTERN.matcher(trySequence); if (matcher.find()) { // abbreviation definition int openingStart = nextNonSpace + matcher.start(); int openingEnd = nextNonSpace + matcher.end(); BasedSequence openingMarker = line.subSequence(openingStart, openingStart + 2); BasedSequence text = line.subSequence(openingStart + 2, openingEnd - 2).trim(); BasedSequence closingMarker = line.subSequence(openingEnd - 2, openingEnd); int contentOffset = options.contentIndent; EnumeratedReferenceBlockParser enumeratedReferenceBlockParser = new EnumeratedReferenceBlockParser(options, contentOffset); enumeratedReferenceBlockParser.block.setOpeningMarker(openingMarker); enumeratedReferenceBlockParser.block.setText(text); enumeratedReferenceBlockParser.block.setClosingMarker(closingMarker); return BlockStart.of(enumeratedReferenceBlockParser) .atIndex(openingEnd); } else { return BlockStart.none(); } } }
@Override public BlockContinue tryContinue(ParserState state) { final int nonSpaceIndex = state.getNextNonSpaceIndex(); if (state.isBlank()) { if (block.getFirstChild() == null) { // Blank line after empty list item return BlockContinue.none(); } else { return BlockContinue.atIndex(nonSpaceIndex); } } if (state.getIndent() >= options.contentIndent) { int contentIndent = state.getIndex() + options.contentIndent; return BlockContinue.atIndex(contentIndent); } else { return BlockContinue.none(); } }
@Override public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockParser) { if (state.getIndent() >= 4) { return BlockStart.none(); } BasedSequence line = state.getLine(); int nextNonSpace = state.getNextNonSpaceIndex(); BasedSequence trySequence = line.subSequence(nextNonSpace, line.length()); Matcher matcher = ABBREVIATION_BLOCK.matcher(trySequence); if (matcher.find()) { // abbreviation definition int openingStart = nextNonSpace + matcher.start(); int openingEnd = nextNonSpace + matcher.end(); BasedSequence openingMarker = trySequence.subSequence(openingStart, openingStart + 2); BasedSequence text = trySequence.subSequence(openingStart + 2, openingEnd - 2).trim(); BasedSequence closingMarker = trySequence.subSequence(openingEnd - 2, openingEnd); AbbreviationBlockParser abbreviationBlock = new AbbreviationBlockParser(); abbreviationBlock.block.setOpeningMarker(openingMarker); abbreviationBlock.block.setText(text); abbreviationBlock.block.setClosingMarker(closingMarker); abbreviationBlock.block.setAbbreviation(trySequence.subSequence(matcher.end()).trim()); abbreviationBlock.block.setCharsFromContent(); return BlockStart.of(abbreviationBlock) .atIndex(line.length()); } else { return BlockStart.none(); } } }
@Override public BlockContinue tryContinue(ParserState state) { final int nonSpaceIndex = state.getNextNonSpaceIndex(); if (state.isBlank()) { if (block.getFirstChild() == null) { // Blank line after empty list item return BlockContinue.none(); } else { return BlockContinue.atIndex(nonSpaceIndex); } } if (state.getIndent() >= options.contentIndent) { int contentIndent = state.getIndex() + options.contentIndent; return BlockContinue.atIndex(contentIndent); } else { return BlockContinue.none(); } }
public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockParser) { int nextNonSpace = state.getNextNonSpaceIndex(); if (isMarker(state, nextNonSpace) && !endsWithMarker(state.getLine())) { int newColumn = state.getColumn() + state.getIndent() + 1; // optional following space or tab if (Parsing.isSpaceOrTab(state.getLine(), nextNonSpace + 1)) { newColumn++; } return BlockStart.of(new AsideBlockParser(state.getProperties(), state.getLine().subSequence(nextNonSpace, nextNonSpace + 1))).atColumn(newColumn); } else { return BlockStart.none(); } } }
@Override public BlockContinue tryContinue(ParserState state) { int nextNonSpace = state.getNextNonSpaceIndex(); boolean isMarker; if (!state.isBlank() && ((isMarker = isMarker(state, nextNonSpace)) || (continueToBlankLine && lastWasBlankLine == 0))) { int newColumn = state.getColumn() + state.getIndent(); lastWasBlankLine = 0; if (isMarker) { newColumn++; // optional following space or tab if (Parsing.isSpaceOrTab(state.getLine(), nextNonSpace + 1)) { newColumn++; } } return BlockContinue.atColumn(newColumn); } else { if (ignoreBlankLine && state.isBlank()) { lastWasBlankLine++; int newColumn = state.getColumn() + state.getIndent(); return BlockContinue.atColumn(newColumn); } return BlockContinue.none(); } }
@Override public BlockContinue tryContinue(ParserState state) { int nextNonSpace = state.getNextNonSpaceIndex(); boolean isMarker; if (!state.isBlank() && ((isMarker = isMarker(state, nextNonSpace, false, false, allowLeadingSpace, interruptsParagraph, interruptsItemParagraph, withLeadSpacesInterruptsItemParagraph)) || (continueToBlankLine && lastWasBlankLine == 0))) { int newColumn = state.getColumn() + state.getIndent(); lastWasBlankLine = 0; if (isMarker) { newColumn++; // optional following space or tab if (Parsing.isSpaceOrTab(state.getLine(), nextNonSpace + 1)) { newColumn++; } } return BlockContinue.atColumn(newColumn); } else { if (ignoreBlankLine && state.isBlank()) { lastWasBlankLine++; int newColumn = state.getColumn() + state.getIndent(); return BlockContinue.atColumn(newColumn); } return BlockContinue.none(); } }
@Override public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockParser) { int nextNonSpace = state.getNextNonSpaceIndex(); BasedSequence line = state.getLine();
static ItemData parseItemMarker(DefinitionOptions options, ParserState state, boolean isTight) { BasedSequence line = state.getLine(); int markerIndex = state.getNextNonSpaceIndex(); int markerColumn = state.getColumn() + state.getIndent(); int markerIndent = state.getIndent();
public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockParser) { int nextNonSpace = state.getNextNonSpaceIndex(); BlockParser matched = matchedBlockParser.getBlockParser(); boolean inParagraph = matched.isParagraphParser(); boolean inParagraphListItem = inParagraph && matched.getBlock().getParent() instanceof ListItem && matched.getBlock() == matched.getBlock().getParent().getFirstChild(); if (isMarker(state, nextNonSpace, inParagraph, inParagraphListItem, allowLeadingSpace, interruptsParagraph, interruptsItemParagraph, withLeadSpacesInterruptsItemParagraph)) { int newColumn = state.getColumn() + state.getIndent() + 1; // optional following space or tab if (Parsing.isSpaceOrTab(state.getLine(), nextNonSpace + 1)) { newColumn++; } return BlockStart.of(new BlockQuoteParser(state.getProperties(), state.getLine().subSequence(nextNonSpace, nextNonSpace + 1))).atColumn(newColumn); } else { return BlockStart.none(); } } }