Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/6508 fix json response highlighting #6871

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/core/components/highlight-code.jsx
Expand Up @@ -12,6 +12,7 @@ export default class HighlightCode extends Component {
className: PropTypes.string,
downloadable: PropTypes.bool,
fileName: PropTypes.string,
language: PropTypes.string,
canCopy: PropTypes.bool
}

Expand Down Expand Up @@ -39,14 +40,15 @@ export default class HighlightCode extends Component {
}

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"}}

className = className || ""

const codeBlock = get(config, "syntaxHighlight.activated")
? <SyntaxHighlighter
language={language}
className={className + " microlight"}
onWheel={this.preventYScrollingBeyondElement}
style={getStyle(get(config, "syntaxHighlight.theme"))}
Expand Down
4 changes: 3 additions & 1 deletion src/core/components/response-body.jsx
Expand Up @@ -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)) {
Expand Down