HtmlChunk (@NotNull PsiElement element, @NotNull String docstring) { final List<String> origLines = LineTokenizer.tokenizeIntoList(docstring.trim(), false, false); final List<String> updatedLines = StreamEx.of(PyIndentUtil.removeCommonIndent(origLines, true)) .takeWhile(line -> !line.startsWith(">>>")) //TODO: PyConsoleUtil.ORDINARY_PROMPT .toList(); final HtmlBuilder result = new HtmlBuilder(); // reconstruct back, dropping first empty fragment as needed boolean isFirstLine = true; final int tabSize = PythonCodeStyleService.getInstance().getTabSize(element.getContainingFile()); for (@NlsSafe String line : updatedLines) { if (isFirstLine && ourSpacesPattern.matcher(line).matches()) continue; // ignore all initial whitespace if (isFirstLine) { isFirstLine = false; } else { result.br(); } int leadingTabs = 0; while (leadingTabs < line.length() && line.charAt(leadingTabs) == '\t') { leadingTabs++; } if (leadingTabs > 0) { line = StringUtil.repeatSymbol(' ', tabSize * leadingTabs) + line.substring(leadingTabs); } result.append(HtmlChunk.text(line)); } return result.toFragment(); }