Skip to content

Commit

Permalink
render laravel dd() dump output properly (#893)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabist authored Sep 19, 2024
1 parent 3ab4ae7 commit a26d9c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions resources/css/theme-default.style.css
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,11 @@ html {
text-shadow: 0 1px 2px rgba(0, 0, 0, .4)
}

.content blockquote pre.sf-dump,
.content pre pre.sf-dump {
width: 100%;
}

.content .annotation {
background-color: #292929;
color: #fff;
Expand Down
14 changes: 13 additions & 1 deletion resources/js/tryitout.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,30 @@ function handleResponse(endpointId, response, status, headers) {

const responseContentEl = document.querySelector('#execution-response-content-' + endpointId);

// Check if the response contains Laravel's dd() default dump output
const isLaravelDump = response.includes('Sfdump');

// If it's a Laravel dd() dump, use innerHTML to render it safely
if (isLaravelDump) {
responseContentEl.innerHTML = response === '' ? responseContentEl.dataset.emptyResponseText : response;
} else {
// Otherwise, stick to textContent for regular responses
responseContentEl.textContent = response === '' ? responseContentEl.dataset.emptyResponseText : response;
}

// Prettify it if it's JSON
let isJson = false;
try {
const jsonParsed = JSON.parse(response);
if (jsonParsed !== null) {
isJson = true;
response = JSON.stringify(jsonParsed, null, 4);
responseContentEl.textContent = response;
}
} catch (e) {

}
responseContentEl.textContent = response === '' ? responseContentEl.dataset.emptyResponseText : response;

isJson && window.hljs.highlightElement(responseContentEl);
const statusEl = document.querySelector('#execution-response-status-' + endpointId);
statusEl.textContent = ` (${status})`;
Expand Down

0 comments on commit a26d9c9

Please sign in to comment.