CharSequence (@NotNull HighlighterIterator iterator, int offset) { Document document = iterator.getDocument(); CharSequence text = document.getCharsSequence(); char theQuote = text.charAt(offset - 1); // Both isOpeningTripleQuote() and isOpeningQuote() expect iterator to be on the token // of the passed offset, not one character to the right. boolean retreated = false; if (iterator.getStart() == offset) { retreated = true; iterator.retreat(); } try { if (isOpeningTripleQuote(iterator, offset - 1)) { return StringUtil.repeat(String.valueOf(theQuote), 3); } else if (isOpeningSingleQuote(iterator, offset - 1)) { return String.valueOf(theQuote); } return null; } finally { if (retreated) { iterator.advance(); } } }