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:
@@ -12,6 +12,7 @@ export default class HighlightCode extends Component {
|
|||||||
className: PropTypes.string,
|
className: PropTypes.string,
|
||||||
downloadable: PropTypes.bool,
|
downloadable: PropTypes.bool,
|
||||||
fileName: PropTypes.string,
|
fileName: PropTypes.string,
|
||||||
|
language: PropTypes.string,
|
||||||
canCopy: PropTypes.bool
|
canCopy: PropTypes.bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +40,7 @@ export default class HighlightCode extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
let { value, className, downloadable, getConfigs, canCopy } = this.props
|
let { value, className, downloadable, getConfigs, canCopy, language } = this.props
|
||||||
|
|
||||||
const config = getConfigs ? getConfigs() : {syntaxHighlight: {activated: true, theme: "agate"}}
|
const config = getConfigs ? getConfigs() : {syntaxHighlight: {activated: true, theme: "agate"}}
|
||||||
|
|
||||||
@@ -47,6 +48,7 @@ export default class HighlightCode extends Component {
|
|||||||
|
|
||||||
const codeBlock = get(config, "syntaxHighlight.activated")
|
const codeBlock = get(config, "syntaxHighlight.activated")
|
||||||
? <SyntaxHighlighter
|
? <SyntaxHighlighter
|
||||||
|
language={language}
|
||||||
className={className + " microlight"}
|
className={className + " microlight"}
|
||||||
onWheel={this.preventYScrollingBeyondElement}
|
onWheel={this.preventYScrollingBeyondElement}
|
||||||
style={getStyle(get(config, "syntaxHighlight.theme"))}
|
style={getStyle(get(config, "syntaxHighlight.theme"))}
|
||||||
|
|||||||
@@ -94,13 +94,15 @@ export default class ResponseBody extends React.PureComponent {
|
|||||||
// Anything else (CORS)
|
// Anything else (CORS)
|
||||||
} else if (/json/i.test(contentType)) {
|
} else if (/json/i.test(contentType)) {
|
||||||
// JSON
|
// JSON
|
||||||
|
let language = null
|
||||||
try {
|
try {
|
||||||
body = JSON.stringify(JSON.parse(content), null, " ")
|
body = JSON.stringify(JSON.parse(content), null, " ")
|
||||||
|
language = "json"
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
body = "can't parse JSON. Raw result:\n\n" + content
|
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
|
// XML
|
||||||
} else if (/xml/i.test(contentType)) {
|
} else if (/xml/i.test(contentType)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user