Include language in snippets so that their syntax can be highlighted

cURL requests are marked as being bash and cURL responses are marked as
being http. This allows their syntax to be highlighted in the resulting
HTML.
This commit is contained in:
Andy Wilkinson
2014-10-28 15:24:50 +00:00
parent 01e37f1e4f
commit 44d6dfa2c0
4 changed files with 10 additions and 7 deletions

View File

@@ -3,7 +3,7 @@ Andy Wilkinson;
:doctype: book
:toc:
:toclevels: 4
:source-highlighter: prettify
:source-highlighter: highlightjs
[introduction]
= Introduction

View File

@@ -3,7 +3,7 @@ Andy Wilkinson;
:doctype: book
:toc:
:toclevels: 4
:source-highlighter: prettify
:source-highlighter: highlightjs
[introduction]
= Introduction

View File

@@ -28,7 +28,7 @@ public class DocumentationWriter extends PrintWriter {
}
public void shellCommand(final DocumentationAction... actions) throws Exception {
codeBlock(new DocumentationAction() {
codeBlock("bash", new DocumentationAction() {
@Override
public void perform() throws Exception {
@@ -54,8 +54,11 @@ public class DocumentationWriter extends PrintWriter {
super.write(s);
}
public void codeBlock(DocumentationAction... actions) throws Exception {
public void codeBlock(String language, DocumentationAction... actions) throws Exception {
println();
if (language != null) {
println("[source," + language + "]");
}
println("----");
for (DocumentationAction action : actions) {
action.perform();

View File

@@ -51,7 +51,7 @@ public abstract class RestDocumentationResultHandlers {
@Override
public void handle(MvcResult result, DocumentationWriter writer)
throws Exception {
writer.codeBlock(new CurlResponseDocumentationAction(writer, result,
writer.codeBlock("http", new CurlResponseDocumentationAction(writer, result,
getCurlConfiguration()));
}
};
@@ -64,7 +64,7 @@ public abstract class RestDocumentationResultHandlers {
throws Exception {
writer.shellCommand(new CurlRequestDocumentationAction(writer, result,
getCurlConfiguration()));
writer.codeBlock(new CurlResponseDocumentationAction(writer, result,
writer.codeBlock("http", new CurlResponseDocumentationAction(writer, result,
getCurlConfiguration()));
}
};
@@ -195,7 +195,7 @@ public abstract class RestDocumentationResultHandlers {
printStream.close();
}
}
private PrintStream createPrintStream()
throws FileNotFoundException {