void (@NotNull final PsiLanguageInjectionHost host, @NotNull final InjectedLanguagePlaces injectionPlacesRegistrar) { if (!(host instanceof PyStringLiteralExpression)) { return; } final Module module = ModuleUtilCore.findModuleForPsiElement(host); if (module == null || !PyDocumentationSettings.getInstance(module).isAnalyzeDoctest()) return; if (DocStringUtil.getParentDefinitionDocString(host) == host) { int start = 0; int end = host.getTextLength() - 1; final String text = host.getText(); final Pair<String,String> quotes = PyStringLiteralCoreUtil.getQuotes(text); final List<String> strings = StringUtil.split(text, "\n", false); boolean gotExample = false; int currentPosition = 0; int maxPosition = text.length(); boolean endsWithSlash = false; for (String string : strings) { final String trimmedString = string.trim(); if (!trimmedString.startsWith(">>>") && !trimmedString.startsWith("...") && gotExample && start < end) { gotExample = false; if (!endsWithSlash) injectionPlacesRegistrar.addPlace(PyDocstringLanguageDialect.getInstance(), TextRange.create(start, end), null, null); } final String closingQuote = quotes == null ? text.substring(0, 1) : quotes.second; if (endsWithSlash && !trimmedString.endsWith("\\")) { endsWithSlash = false; injectionPlacesRegistrar.addPlace(PyDocstringLanguageDialect.getInstance(), TextRange.create(start, getEndOffset(currentPosition, string, maxPosition, closingQuote)), null, null); } if (trimmedString.startsWith(">>>")) { if (trimmedString.endsWith("\\")) endsWithSlash = true; if (!gotExample) start = currentPosition; gotExample = true; end = getEndOffset(currentPosition, string, maxPosition, closingQuote); } else if (trimmedString.startsWith("...") && gotExample) { if (trimmedString.endsWith("\\")) endsWithSlash = true; end = getEndOffset(currentPosition, string, maxPosition, closingQuote); } currentPosition += string.length(); } if (gotExample && start < end) injectionPlacesRegistrar.addPlace(PyDocstringLanguageDialect.getInstance(), TextRange.create(start, end), null, null); } }