Specify language derived from Content-Type in body snippets
See gh-797
This commit is contained in:
committed by
Andy Wilkinson
parent
bdba92efe7
commit
9a44205253
@@ -73,6 +73,11 @@ public abstract class AbstractBodySnippet extends TemplatedSnippet {
|
||||
protected Map<String, Object> createModel(Operation operation) {
|
||||
try {
|
||||
MediaType contentType = getContentType(operation);
|
||||
String language = null;
|
||||
if (contentType != null) {
|
||||
language = (contentType.getSubtypeSuffix() != null) ? contentType.getSubtypeSuffix()
|
||||
: contentType.getSubtype();
|
||||
}
|
||||
byte[] content = getContent(operation);
|
||||
if (this.subsectionExtractor != null) {
|
||||
content = this.subsectionExtractor.extractSubsection(content, contentType);
|
||||
@@ -80,6 +85,7 @@ public abstract class AbstractBodySnippet extends TemplatedSnippet {
|
||||
Charset charset = extractCharset(contentType);
|
||||
String body = (charset != null) ? new String(content, charset) : new String(content);
|
||||
Map<String, Object> model = new HashMap<>();
|
||||
model.put("language", language);
|
||||
model.put("body", body);
|
||||
return model;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[source,options="nowrap"]
|
||||
[source{{#language}},{{language}}{{/language}},options="nowrap"]
|
||||
----
|
||||
{{body}}
|
||||
----
|
||||
@@ -1,4 +1,4 @@
|
||||
[source,options="nowrap"]
|
||||
[source{{#language}},{{language}}{{/language}},options="nowrap"]
|
||||
----
|
||||
{{body}}
|
||||
----
|
||||
@@ -1,3 +1,3 @@
|
||||
```
|
||||
```{{#language}}{{language}}{{/language}}
|
||||
{{body}}
|
||||
```
|
||||
@@ -1,3 +1,3 @@
|
||||
```
|
||||
```{{#language}}{{language}}{{/language}}
|
||||
{{body}}
|
||||
```
|
||||
Reference in New Issue
Block a user