public void setTextChars(BasedSequence textChars) { int textCharsLength = textChars.length(); this.textOpeningMarker = textChars.subSequence(0, 1); this.text = textChars.subSequence(1, textCharsLength - 1).trim(); this.textClosingMarker = textChars.subSequence(textCharsLength - 1, textCharsLength); }
public GitLabInline(BasedSequence openingMarker, BasedSequence text, BasedSequence closingMarker) { super(openingMarker.baseSubSequence(openingMarker.getStartOffset(), closingMarker.getEndOffset())); this.openingMarker = openingMarker; this.text = text; this.closingMarker = closingMarker; }
public int length() { int total = 0; BasedSequence last = null; for (BasedSequence s : segments) { if (s.isEmpty()) continue; if (last != null && last.getEndOffset() < s.getStartOffset() && (BasedSequence.WHITESPACE_CHARS.indexOf(last.charAt(last.length() - 1)) == -1) && BasedSequence.WHITESPACE_CHARS.indexOf(s.charAt(0)) == -1) { total++; } total++; last = s; } return total; }
public void setReferenceChars(BasedSequence referenceChars) { int referenceCharsLength = referenceChars.length(); int openingOffset = referenceChars.charAt(0) == '!' ? 2 : 1; this.referenceOpeningMarker = referenceChars.subSequence(0, openingOffset); this.reference = referenceChars.subSequence(openingOffset, referenceCharsLength - 1).trim(); this.referenceClosingMarker = referenceChars.subSequence(referenceCharsLength - 1, referenceCharsLength); }
@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 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.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 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 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) { 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) { 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(); 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(); } }
@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(); } }
/** * Parse a backslash-escaped special character, adding either the escaped character, a hard line break * (if the backslash is followed by a newline), or a literal backslash to the block's children. * * @return true */ protected boolean parseBackslash() { index++; if (peek() == '\n' || peek() == '\r') { int charsMatched = peek(1) == '\n' ? 2 : 1; appendNode(new HardLineBreak(input.subSequence(index - 1, index + charsMatched))); index += charsMatched; } else if (index < input.length() && myParsing.ESCAPABLE.matcher(input.subSequence(index, index + 1)).matches()) { appendText(input, index - 1, index + 1); index++; } else { appendText(input.subSequence(index - 1, index)); } return true; }
@Override public boolean parse(final InlineParser inlineParser) { if (inlineParser.peek(1) == '`') { BasedSequence input = inlineParser.getInput(); Matcher matcher = inlineParser.matcher(MATH_PATTERN); if (matcher != null) { inlineParser.flushTextNode(); BasedSequence mathOpen = input.subSequence(matcher.start(), matcher.start(1)); BasedSequence mathClosed = input.subSequence(matcher.end(1), matcher.end()); GitLabInlineMath inlineMath = new GitLabInlineMath(mathOpen, mathOpen.baseSubSequence(mathOpen.getEndOffset(),mathClosed.getStartOffset()), mathClosed); inlineParser.getBlock().appendChild(inlineMath); return true; } } return false; }
private void render(MailLink node, NodeRendererContext context, HtmlWriter html) { String text = node.getText().unescape(); if (context.isDoNotRenderLinks()) { html.text(text); } else { ResolvedLink resolvedLink = context.resolveLink(LinkType.LINK, text, null); html.raw("[").raw(text).raw("|mailto:").raw(resolvedLink.getUrl()).raw("]"); } }
private void renderEmbedLink(final EmbedLink node, final NodeRendererContext context, final HtmlWriter html) { if (context.isDoNotRenderLinks()) { context.renderChildren(node); } else { ResolvedLink resolvedLink = context.resolveLink(LinkType.LINK, node.getUrl().unescape(), null); html.attr("title", node.getText()) .attr("src", resolvedLink.getUrl()) .withAttr() .tag("embed", true); } }
@Override public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockParser) { BasedSequence line = state.getLine(); if (state.getIndex() == 0) { int breakLength = myOptions.exampleBreak.length(); if (line.length() >= breakLength + 1 + EXAMPLE_KEYWORD.length() && line.startsWith(myOptions.exampleBreak) && line.matchChars(EXAMPLE_KEYWORD, breakLength + 1) && " \t\u00A0".contains(String.valueOf(line.charAt(breakLength)))) { SpecExampleBlockParser blockParser = new SpecExampleBlockParser(state.getProperties()); blockParser.block.setOpeningMarker(line.subSequence(0, breakLength)); //blockParser.addLine(state, state.getLineWithEOL()); return BlockStart.of(blockParser).atIndex(-1); } } return BlockStart.none(); } }
void render(Link node, NodeRendererContext context, HtmlWriter html) { if (context.isDoNotRenderLinks() || isSuppressedLinkPrefix(node.getUrl(), context)) { context.renderChildren(node); } else { ResolvedLink resolvedLink = context.resolveLink(LinkType.LINK, node.getUrl().unescape(), null, null); html.attr("href", resolvedLink.getUrl()); // we have a title part, use that if (node.getTitle().isNotNull()) { resolvedLink.getNonNullAttributes().replaceValue(Attribute.TITLE_ATTR, node.getTitle().unescape()); } else { resolvedLink.getNonNullAttributes().remove(Attribute.TITLE_ATTR); } html.attr(resolvedLink.getAttributes()); html.srcPos(node.getChars()).withAttr(resolvedLink).tag("a"); renderChildrenSourceLineWrapped(node, node.getText(), context, html); html.tag("/a"); } }
private void render(WikiImage node, NodeRendererContext context, HtmlWriter html) { if (!context.isDoNotRenderLinks()) { if (options.disableRendering) { html.text(node.getChars().unescape()); } else { String altText = node.getText().isNotNull() ? node.getText().toString() : node.getLink().unescape(); ResolvedLink resolvedLink = context.resolveLink(WikiLinkExtension.WIKI_LINK, node.getLink().unescape(), null); String url = resolvedLink.getUrl(); html.attr("src", url); html.attr("alt", altText); html.srcPos(node.getChars()).withAttr(resolvedLink).tagVoid("img"); } } }