CharSequence (String root, @NotNull CharSequence read) { StringBuilder ready = new StringBuilder(); int prev = 0; Matcher matcher = mySelector.matcher(read); while (matcher.find()) { CharSequence before = read.subSequence(prev, matcher.start(1) - 1); // Before reference CharSequence href = read.subSequence(matcher.start(1), matcher.end(1)); // The URL prev = matcher.end(1) + 1; ready.append(before); ready.append("\""); ready.append(ReadAction.compute(() -> convertReference(root, href.toString()))); ready.append("\""); } ready.append(read, prev, read.length()); return ready; }