Skip to content

Commit

Permalink
T257788: Detect missing space before internal link (suggestions)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas authored and Nicolas committed Jul 26, 2020
1 parent 3209f06 commit d502a98
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public boolean analyzeLink(
if (beginIndex == 0) {
return false;
}
char previousChar = analysis.getContents().charAt(beginIndex - 1);
String contents = analysis.getContents();
char previousChar = contents.charAt(beginIndex - 1);
if (!Character.isLetter(previousChar)) {
return false;
}
Expand All @@ -83,9 +84,25 @@ public boolean analyzeLink(
if (errors == null) {
return true;
}
beginIndex--;
while ((beginIndex > 0) &&
Character.isLetter(contents.charAt(beginIndex - 1))) {
beginIndex--;
}
int endIndex = link.getEndIndex();
CheckErrorResult errorResult = createCheckErrorResult(analysis, beginIndex, endIndex);
String replacement =
contents.substring(beginIndex, link.getBeginIndex()) +
" " +
contents.substring(link.getBeginIndex(), link.getEndIndex());
errorResult.addReplacement(replacement);
if ((beginIndex <= 0) ||
Character.isWhitespace(contents.charAt(beginIndex - 1))) {
replacement = PageElementInternalLink.createInternalLink(
link.getLink(),
link.getAnchor(),
contents.substring(beginIndex, link.getBeginIndex()) + link.getDisplayedText());
errorResult.addReplacement(replacement);
}
errors.add(errorResult);
return true;
}
Expand Down

0 comments on commit d502a98

Please sign in to comment.