MarkdownUtil { public static void replaceHeaders(@NotNull List<String> lines) { for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); int ind = 0; while (ind < line.length() && line.charAt(ind) == '#') { ind++; } if (ind < line.length() && line.charAt(ind) == ' ') { if (0 < ind && ind <= 9) { int endInd = line.length() - 1; while (endInd >= 0 && line.charAt(endInd) == '#') { endInd--; } line = line.substring(ind + 1, endInd + 1); line = "<h" + ind + ">" + line + "</h" + ind + ">"; lines.set(i, line); } } } } private  MarkdownUtil(); static void replaceHeaders(@NotNull List<String> lines); static void removeImages(@NotNull List<String> lines); static void replaceCodeBlock(@NotNull List<String> lines); static void generateLists(@NotNull List<String> lines);  }
@Test public void testReplaceHeaders() throws Exception { List<String> markdown = ContainerUtil.newArrayList("# Hello1", "## Hello2##", "### Hello3#"); MarkdownUtil.replaceHeaders(markdown); Assert.assertEquals(ContainerUtil.newArrayList("<h1>Hello1</h1>", "<h2>Hello2</h2>", "<h3>Hello3</h3>"), markdown); }