@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) { // we stop on a blank line if blank line spacer is not enabled or we already had one if ((!options.isBlankLineSpacer || haveChildren != 0) && state.isBlank()) { return BlockContinue.none(); } else { if (state.isBlank()) { haveChildren |= HAVE_BLANK_LINE; blankLineSpacer = state.getLine(); } return BlockContinue.atIndex(state.getIndex()); } }
@Override public BlockContinue tryContinue(ParserState state) { if (hadClose) { return BlockContinue.none(); final BasedSequence line = state.getLine(); final Matcher closeMatcher = parsing.MACRO_CLOSE.matcher(line); if (closeMatcher.find()) { if (macroName.equals(closeMatcher.group(1))) { final List<BlockParser> parsers = state.getActiveBlockParsers(); boolean isChildClose = false; for (int i = parsers.size(); i-- > 0; ) { MacroClose macroClose = new MacroClose(line.subSequence(closeMatcher.start(), closeMatcher.start() + 3), line.subSequence(closeMatcher.start(1), closeMatcher.end(1)), line.subSequence(closeMatcher.end() - 2, closeMatcher.end())); return BlockContinue.atIndex(state.getLineEndIndex()); return BlockContinue.atIndex(state.getIndex());
@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(); } }
static boolean isMarker(ParserState state, int index) { CharSequence line = state.getLine(); return state.getIndent() < state.getParsing().CODE_BLOCK_INDENT && index < line.length() && line.charAt(index) == '|'; }
@Override public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockParser) { if (state.getIndent() >= 4) { return BlockStart.none(); 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(); BasedSequence line = state.getLine(); BasedSequence trySequence = line.subSequence(nextNonSpace, line.length()); Parsing parsing = state.getParsing(); Pattern startPattern = Pattern.compile(String.format(ADMONITION_START_FORMAT, parsing.ATTRIBUTENAME, parsing.LINK_TITLE_STRING)); Matcher matcher = startPattern.matcher(trySequence); if (matcher.find()) { BasedSequence openingMarker = line.subSequence(nextNonSpace + matcher.start(1), nextNonSpace + matcher.end(1)); BasedSequence info = line.subSequence(nextNonSpace + matcher.start(2), nextNonSpace + matcher.end(2)); BasedSequence titleChars = matcher.group(3) == null ? BasedSequence.NULL : line.subSequence(nextNonSpace + matcher.start(3), nextNonSpace + matcher.end(3)); admonitionBlockParser.block.setTitleChars(titleChars); return BlockStart.of(admonitionBlockParser) .atIndex(line.length()); } else { return BlockStart.none();
@Override public BlockContinue tryContinue(ParserState state) { final BasedSequence line = state.getLine(); if (inYAMLBlock) { Matcher matcher = JEKYLL_FRONT_MATTER_BLOCK_END.matcher(line); if (matcher.matches()) { block.setClosingMarker(line.subSequence(matcher.start(1), matcher.end(1))); return BlockContinue.finished(); } return BlockContinue.atIndex(state.getIndex()); } else if (JEKYLL_FRONT_MATTER_BLOCK_START.matcher(line).matches()) { inYAMLBlock = true; return BlockContinue.atIndex(state.getIndex()); } return BlockContinue.none(); }
@Override public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockParser) { if (state.getIndent() >= 4 || options.noLeadSpace && state.getIndent() >= 1) { return BlockStart.none(); if (state.getActiveBlockParser() instanceof FencedCodeBlockParser) { return BlockStart.none(); return BlockStart.none(); BasedSequence line = state.getLine(); int nextNonSpace = state.getNextNonSpaceIndex(); BasedSequence paragraph = matchedBlockParser.getParagraphContent(); Matcher matcher; BasedSequence trySequence = line.subSequence(nextNonSpace, line.length()); matcher = myParsing.ATX_HEADING.matcher(trySequence); if (matcher.find()) { content.add(state.getLineWithEOL().subSequence(newOffset), state.getIndent()); matcher = myParsing.ATX_TRAILING.matcher(headerText); if ((matcher = myParsing.SETEXT_HEADING.matcher(trySequence)).find()) { if (paragraph != null) { content.addAll(matchedBlockParser.getParagraphLines(), matchedBlockParser.getParagraphEolLengths());
@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 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) { BasedSequence line = state.getLine(); int currentIndent = state.getIndent(); if (currentIndent == 0 && !(matchedBlockParser.getBlockParser().getBlock() instanceof Paragraph)) { final BasedSequence tryLine = line.subSequence(state.getIndex()); Matcher matcher = parsing.MACRO_OPEN.matcher(tryLine); if (matcher.find()) { isClosedTag = true; } else { return BlockStart.none(); return BlockStart.none(); Matcher attributeMatcher = parsing.MACRO_ATTRIBUTE.matcher(attributeText); while (attributeMatcher.find()) { BasedSequence attributeName = attributeText.subSequence(attributeMatcher.start(1), attributeMatcher.end(1)); final MacroBlockParser parser = new MacroBlockParser(state.getProperties(), parsing, macroName, oneLine); if (oneLine) { parser.hadClose = true; if (macroClose != null) parser.block.appendChild(macroClose); return BlockStart.of(parser) .atIndex(state.getLineEndIndex())
Parsing parsing = state.getParsing(); BasedSequence line = state.getLine(); int markerIndex = state.getNextNonSpaceIndex(); int markerColumn = state.getColumn() + state.getIndent(); int markerIndent = state.getIndent(); BasedSequence rest = line.subSequence(markerIndex, line.length()); Matcher matcher = parsing.LIST_ITEM_MARKER.matcher(rest); if (!matcher.find()) { return null; int markerLength = matcher.end() - matcher.start(); boolean isNumberedList = !"+-*".contains(matcher.group()); int indexAfterMarker = markerIndex + markerLength; for (int i = indexAfterMarker; i < line.length(); i++) { char c = line.charAt(i); if (c == '\t') {
@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.getIndex() == 0 && !haveBlockQuoteParser(state)) { BasedSequence line = state.getLineWithEOL(); final Matcher matcher = (state.getParsing().intellijDummyIdentifier ? MACRO_BLOCK_START_INTELLIJ : MACRO_BLOCK_START).matcher(line); if (matcher.matches()) { return BlockStart.of(new MacroDefinitionBlockParser(state.getProperties(), line.subSequence(0, 3), line.subSequence(matcher.start(1), matcher.end(1)), line.subSequence(matcher.start(2), matcher.end(1)))) .atIndex(state.getLineEndIndex()) //.replaceActiveBlockParser() ; } } return BlockStart.none(); } }
@Override public BlockContinue tryContinue(ParserState state) { if (hadClose) { return BlockContinue.none(); } final int index = state.getIndex(); BasedSequence line = state.getLineWithEOL(); final Matcher matcher = GIT_LAB_BLOCK_END.matcher(line.subSequence(index)); if (!matcher.matches()) { return BlockContinue.atIndex(index); } else { // if have open gitlab block quote last child then let them handle it Node lastChild = block.getLastChild(); if (lastChild instanceof GitLabBlockQuote) { final BlockParser parser = state.getActiveBlockParser((Block) lastChild); if (parser instanceof GitLabBlockQuoteParser && !((GitLabBlockQuoteParser) parser).hadClose) { // let the child handle it return BlockContinue.atIndex(index); } } hadClose = true; block.setClosingMarker(state.getLine().subSequence(index, index + 3)); block.setClosingTrailing(state.getLineWithEOL().subSequence(matcher.start(1), matcher.end(1))); return BlockContinue.atIndex(state.getLineEndIndex()); } }
@Override public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockParser) { BasedSequence line = state.getLine(); int currentIndent = state.getIndent(); if (currentIndent == 0 && !(matchedBlockParser.getBlockParser().getBlock() instanceof Paragraph)) { final BasedSequence tryLine = line.subSequence(state.getIndex()); Matcher matcher = parsing.MACRO_OPEN.matcher(tryLine); if (matcher.find()) { // see if it closes on the same line, then we create a block and close it BasedSequence tag = tryLine.subSequence(0, matcher.end()); BasedSequence tagName = line.subSequence(matcher.start(1), matcher.end(1)); BasedSequence parameters = tryLine.subSequence(matcher.end(1), matcher.end() - 2).trim(); JekyllTag tagNode = new JekyllTag(tag.subSequence(0, 2), tagName, parameters, tag.endSequence(2)); tagNode.setCharsFromContent(); final JekyllTagBlockParser parser = new JekyllTagBlockParser(state.getProperties()); parser.block.appendChild(tagNode); //noinspection EqualsBetweenInconvertibleTypes if (!listIncludesOnly || tagName.equals(INCLUDE_TAG)) { List<JekyllTag> tagList = JekyllTagExtension.TAG_LIST.getFrom(state.getProperties()); tagList.add(tagNode); } return BlockStart.of(parser) .atIndex(state.getLineEndIndex()) ; } } return BlockStart.none(); } }
@Override public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockParser) { int nextNonSpace = state.getNextNonSpaceIndex(); BasedSequence line = state.getLine(); if (state.getIndent() < 4 && line.charAt(nextNonSpace) == '<' && !(matchedBlockParser.getBlockParser() instanceof HtmlBlockParser)) { if (myHtmlBlockDeepParser) { HtmlDeepParser deepParser = new HtmlDeepParser(Parser.HTML_BLOCK_TAGS.getFrom(state.getProperties())); deepParser.parseHtmlChunk(line.subSequence(nextNonSpace, line.length()), myHtmlBlockStartOnlyOnBlockTags, myHtmlBlockDeepParseNonBlock, myHtmlBlockDeepParseFirstOpenTagOnOneLine); if (deepParser.hadHtml()) { if (((deepParser.getHtmlMatch() == OPEN_TAG || (!myHtmlCommentBlocksInterruptParagraph && deepParser.getHtmlMatch() == COMMENT)) && matchedBlockParser.getBlockParser().getBlock() instanceof Paragraph)) { } else { return BlockStart.of(new HtmlBlockParser(state.getProperties(), null, deepParser.getHtmlMatch() == COMMENT, deepParser)).atIndex(state.getIndex()); for (int blockType = 1; blockType <= 7; blockType++) { if (blockType == 7 && (myHtmlBlockStartOnlyOnBlockTags || matchedBlockParser.getBlockParser().getBlock() instanceof Paragraph)) { continue; myPatterns = new Patterns(state.getParsing(), state.getProperties()); final Matcher matcher = opener.matcher(line.subSequence(nextNonSpace, line.length())); boolean matches = matcher.find(); return BlockStart.of(new HtmlBlockParser(state.getProperties(), closer, blockType == myPatterns.COMMENT_PATTERN_INDEX, null)).atIndex(state.getIndex());
@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 BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockParser) { BasedSequence line = state.getLine(); List<BasedSequence> paragraphLines = matchedBlockParser.getParagraphLines(); if (paragraphLines != null && paragraphLines.size() >= 1 && paragraphLines.size() <= maxHeaderRows && paragraphLines.get(0).toString().contains("|")) { BasedSequence separatorLine = line.subSequence(state.getIndex(), line.length()); if (TABLE_HEADER_SEPARATOR.matcher(separatorLine).matches()) { BasedSequence paragraph = paragraphLines.get(0); List<BasedSequence> headParts = split(paragraph); List<BasedSequence> separatorParts = split(separatorLine); if (separatorParts.size() >= headParts.size()) { TableBlockParser tableBlockParser = new TableBlockParser(); tableBlockParser.addLine(state, paragraph); tableBlockParser.nextIsSeparatorLine = true; return BlockStart.of(tableBlockParser) .atIndex(state.getIndex()) .replaceActiveBlockParser(); } } } return BlockStart.none(); } }
@Override public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockParser) { BasedSequence line = state.getLine(); BlockParser parentParser = matchedBlockParser.getBlockParser(); if (parentParser instanceof DocumentBlockParser && parentParser.getBlock().getFirstChild() == null) { Matcher matcher = JEKYLL_FRONT_MATTER_BLOCK_START.matcher(line); if (matcher.matches()) { BasedSequence openingMarker = line.subSequence(0, 3); JekyllFrontMatterBlockParser parser = new JekyllFrontMatterBlockParser(state.getProperties(), openingMarker); return BlockStart.of(parser).atIndex(-1); } } return BlockStart.none(); } }