MarkdownLinkFilterWriter extends Writer { @Override public void write(char[] cbuf, int off, int len) throws IOException { StringBuffer slurped = new StringBuffer(); for (int i = 0; i < len; i++) { slurped.append(cbuf[i + off]); } String replaced = String.format(slurped.toString(), dest); String markedDown = new MarkdownProcessor().markdown(replaced); markedDown = markedDown.replace("<p>", ""); markedDown = markedDown.replace("</p>", ""); out.write(markedDown); } MarkdownLinkFilterWriter(Writer out, String dest); @Override void write(char[] cbuf, int off, int len); @Override void flush(); @Override void close();  }
@Test public void testMarkupEnglish() throws Exception { char[] characterBuffer = "You can also [define a new question](%s)".toCharArray(); markdownLinkFilterWriter.write(characterBuffer, 0, 40); Mockito.verify(out).write("You can also <a href=\"createQuestion.ftl\">define a new question</a>\n"); }
@Test public void testMarkupFrench() throws Exception { char[] characterBuffer = "Vous pouvez aussi [créer une nouvelle question](%s)".toCharArray(); new MarkdownLinkFilterWriter(out, link).write(characterBuffer, 0, 51); Mockito.verify(out).write("Vous pouvez aussi <a href=\"createQuestion.ftl\">créer une nouvelle question</a>\n"); }
@Test public void testMarkupChinese() throws Exception { char[] characterBuffer = "你也可以[定义新问题](%s)".toCharArray(); new MarkdownLinkFilterWriter(out, link).write(characterBuffer, 0, 15); Mockito.verify(out).write("你也可以<a href=\"createQuestion.ftl\">定义新问题</a>\n"); }