fix(responseBody): json response highlighting (#6871)

Refs #6508 

* Add language prop to HighlightCode component

* Use language prop for JSON HighlightCode responses in response-body.jsx
This commit is contained in:
Nicolas
2021-02-03 17:56:29 -03:00
committed by GitHub
parent 5c4dfc2da8
commit 13fea13397
2 changed files with 6 additions and 2 deletions

View File

@@ -94,13 +94,15 @@ export default class ResponseBody extends React.PureComponent {
// Anything else (CORS)
} else if (/json/i.test(contentType)) {
// JSON
let language = null
try {
body = JSON.stringify(JSON.parse(content), null, " ")
language = "json"
} catch (error) {
body = "can't parse JSON. Raw result:\n\n" + content
}
bodyEl = <HighlightCode downloadable fileName={`${downloadName}.json`} value={ body } getConfigs={ getConfigs } canCopy />
bodyEl = <HighlightCode language={language} downloadable fileName={`${downloadName}.json`} value={ body } getConfigs={ getConfigs } canCopy />
// XML
} else if (/xml/i.test(contentType)) {