Commit 208a9b77 authored by Viraj Shah's avatar Viraj Shah

Refactor creation of text in MarkdownResultPage

parent bf70c0e5
Pipeline #113353 passed with stages
in 52 seconds
......@@ -14,20 +14,25 @@ public class MarkdownResultPage implements Page {
this.answer = answer;
}
public String createMarkdownText() {
StringBuilder stringBuilder = new StringBuilder();
if (answer == null || answer.isEmpty()) {
stringBuilder.append("# Sorry\n");
stringBuilder.append("Sorry, we didn't understand: *").append(query).append( "*\n");
stringBuilder.append("\n");
} else {
stringBuilder.append("#").append(query).append("\n");
stringBuilder.append(answer).append("\n");
}
return stringBuilder.toString();
}
public void writeTo(HttpServletResponse resp) throws IOException {
resp.setContentType("text/markdown");
resp.setHeader("Content-Disposition", "attachment;filename=result.md");
PrintWriter writer = resp.getWriter();
// Content
if (answer == null || answer.isEmpty()) {
writer.println("# Sorry");
writer.println("Sorry, we didn't understand: *" + query + "*");
writer.println("");
} else {
writer.println("# " + query);
writer.println(answer);
}
writer.write(createMarkdownText());
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment