List<FileReference> (String str, int startInElement) { int wsHead = 0; int wsTail = 0; LiteralTextEscaper<? extends PsiLanguageInjectionHost> escaper; TextRange valueRange; CharSequence decoded; // todo replace @param str with honest @param rangeInElement; and drop the following startsWith(..) if (myElement instanceof PsiLanguageInjectionHost && !StringUtil.startsWith(myElement.getText(), startInElement, str)) { escaper = ((PsiLanguageInjectionHost)myElement).createLiteralTextEscaper(); valueRange = ElementManipulators.getValueTextRange(myElement); StringBuilder sb = new StringBuilder(); escaper.decode(valueRange, sb); decoded = sb; wsHead += Math.max(0, startInElement - valueRange.getStartOffset()); } else { escaper = null; decoded = str; valueRange = TextRange.from(startInElement, decoded.length()); } List<FileReference> referencesList = new ArrayList<>(); for (int i = wsHead; i < decoded.length() && Character.isWhitespace(decoded.charAt(i)); i++) { wsHead++; // skip head white spaces } for (int i = decoded.length() - 1; i >= 0 && Character.isWhitespace(decoded.charAt(i)); i--) { wsTail++; // skip tail white spaces } int index = 0; int curSep = findSeparatorOffset(decoded, wsHead); int sepLen = curSep >= wsHead ? findSeparatorLength(decoded, curSep) : 0; if (curSep >= 0 && decoded.length() == wsHead + sepLen + wsTail) { // add extra reference for the only & leading "/" TextRange r = TextRange.create(startInElement, offset(curSep + Math.max(0, sepLen - 1), escaper, valueRange) + 1); FileReference reference = createFileReference(r, index++, decoded.subSequence(curSep, curSep + sepLen).toString()); if (reference != null) { referencesList.add(reference); } } curSep = curSep == wsHead ? curSep + sepLen : wsHead; // reset offsets & start again for simplicity sepLen = 0; while (curSep >= 0) { int nextSep = findSeparatorOffset(decoded, curSep + sepLen); int start = curSep + sepLen; int endTrimmed = nextSep > 0 ? nextSep : Math.max(start, decoded.length() - wsTail); // todo move ${placeholder} support (the str usage below) to a reference implementation // todo reference-set should be bound to exact range & text in a file, consider: ${slash}path${slash}file&amp;.txt String refText = index == 0 && nextSep < 0 && !StringUtil.contains(decoded, str) ? str : decoded.subSequence(start, endTrimmed).toString(); int refStart = offset(start, escaper, valueRange); int refEnd = offset(endTrimmed, escaper, valueRange); if (!(refStart <= refEnd && refStart >= 0)) { LOG.error("Invalid range: (" + (refText + ", " + refEnd) + "), escaper=" + escaper + "\n" + "text=" + refText + ", start=" + startInElement); } FileReference reference = createFileReference(new TextRange(refStart, refEnd), index++, refText); if (reference != null) { referencesList.add(reference); } curSep = nextSep; sepLen = curSep > 0 ? findSeparatorLength(decoded, curSep) : 0; } return referencesList; }