@Test public void eligibleForReferenceDefinitionLinkStartOfLine() { PotentialBracketEndDelimiter delimiter = new PotentialBracketEndDelimiter(line, 0); assertTrue(delimiter.eligibleForReferenceDefinition(new PotentialBracketDelimiter(line, 0, 1, "["), Cursors.createCursor("["))); assertTrue(delimiter.eligibleForReferenceDefinition(new PotentialBracketDelimiter(line, 2, 1, "["), Cursors.createCursor("a\n["))); }
boolean eligibleForReferenceDefinition(PotentialBracketDelimiter openingDelimiter, Cursor cursor) { boolean linkDelimiter = openingDelimiter.isLinkDelimiter(); if (!linkDelimiter) { return false; } int cursorRelativeOffset = cursor.toCursorOffset(openingDelimiter.getOffset()); for (int x = cursorRelativeOffset - 1; x >= 0; --x) { char c = cursor.getChar(x); if (c == '\n') { return true; } else if (c != ' ') { return false; } if (cursorRelativeOffset - x == 4) { return false; } } int cursorRelativeEndOffset = cursor.toCursorOffset(getOffset()); for (int x = cursorRelativeOffset + 1; x < cursorRelativeEndOffset; ++x) { char c = cursor.getChar(x); if (c == '[' && !precededByBackslashEscape(cursor, x)) { return false; } } return true; }
PotentialBracketEndDelimiter extends InlineWithText { boolean eligibleForReferenceDefinition(PotentialBracketDelimiter openingDelimiter, Cursor cursor) { boolean linkDelimiter = openingDelimiter.isLinkDelimiter(); if (!linkDelimiter) { return false; } int cursorRelativeOffset = cursor.toCursorOffset(openingDelimiter.getOffset()); for (int x = cursorRelativeOffset - 1; x >= 0; --x) { char c = cursor.getChar(x); if (c == '\n') { return true; } else if (c != ' ') { return false; } if (cursorRelativeOffset - x == 4) { return false; } } int cursorRelativeEndOffset = cursor.toCursorOffset(getOffset()); for (int x = cursorRelativeOffset + 1; x < cursorRelativeEndOffset; ++x) { char c = cursor.getChar(x); if (c == '[' && !precededByBackslashEscape(cursor, x)) { return false; } } return true; } }
PotentialBracketEndDelimiter extends InlineWithText { boolean eligibleForReferenceDefinition(PotentialBracketDelimiter openingDelimiter, Cursor cursor) { boolean linkDelimiter = openingDelimiter.isLinkDelimiter(); if (!linkDelimiter) { return false; } int cursorRelativeOffset = cursor.toCursorOffset(openingDelimiter.getOffset()); for (int x = cursorRelativeOffset - 1; x >= 0; --x) { char c = cursor.getChar(x); if (c == '\n') { return true; } else if (c != ' ') { return false; } if (cursorRelativeOffset - x == 4) { return false; } } int cursorRelativeEndOffset = cursor.toCursorOffset(getOffset()); for (int x = cursorRelativeOffset + 1; x < cursorRelativeEndOffset; ++x) { char c = cursor.getChar(x); if (c == '[' && !precededByBackslashEscape(cursor, x)) { return false; } } return true; } PotentialBracketEndDelimiter(Line line, int offset); }
PotentialBracketEndDelimiter extends InlineWithText { boolean eligibleForReferenceDefinition(PotentialBracketDelimiter openingDelimiter, Cursor cursor) { boolean linkDelimiter = openingDelimiter.isLinkDelimiter(); if (!linkDelimiter) { return false; } int cursorRelativeOffset = cursor.toCursorOffset(openingDelimiter.getOffset()); for (int x = cursorRelativeOffset - 1; x >= 0; --x) { char c = cursor.getChar(x); if (c == '\n') { return true; } else if (c != ' ') { return false; } if (cursorRelativeOffset - x == 4) { return false; } } int cursorRelativeEndOffset = cursor.toCursorOffset(getOffset()); for (int x = cursorRelativeOffset + 1; x < cursorRelativeEndOffset; ++x) { char c = cursor.getChar(x); if (c == '[' && !precededByBackslashEscape(cursor, x)) { return false; } } return true; } PotentialBracketEndDelimiter(Line line, int offset); @Override void emit(DocumentBuilder builder); @Override void apply(ProcessingContext context, List<Inline> inlines, Cursor cursor); void truncate(List<Inline> inlines, int indexOfOpeningDelimiter); }
PotentialBracketEndDelimiter extends InlineWithText { boolean eligibleForReferenceDefinition(PotentialBracketDelimiter openingDelimiter, Cursor cursor) { boolean linkDelimiter = openingDelimiter.isLinkDelimiter(); if (!linkDelimiter) { return false; } int cursorRelativeOffset = cursor.toCursorOffset(openingDelimiter.getOffset()); for (int x = cursorRelativeOffset - 1; x >= 0; --x) { char c = cursor.getChar(x); if (c == '\n') { return true; } else if (c != ' ') { return false; } if (cursorRelativeOffset - x == 4) { return false; } } int cursorRelativeEndOffset = cursor.toCursorOffset(getOffset()); for (int x = cursorRelativeOffset + 1; x < cursorRelativeEndOffset; ++x) { char c = cursor.getChar(x); if (c == '[' && !precededByBackslashEscape(cursor, x)) { return false; } } return true; } PotentialBracketEndDelimiter(Line line, int offset); @Override void emit(DocumentBuilder builder); @Override void apply(ProcessingContext context, List<Inline> inlines, Cursor cursor); void truncate(List<Inline> inlines, int indexOfOpeningDelimiter);  }