File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 120120 initializeSliderValues();
121121
122122 // Fix for preserving leading whitespace in HTMX responses
123+ // We need to handle both colored text (HTML) and preserve whitespace
123124 document.body.addEventListener ('htmx:beforeSwap', function(evt) {
124125 if (evt.detail.target.id === 'result-code') {
125- evt.detail.shouldSwap = true;
126- evt.detail.target.textContent = evt.detail.xhr.responseText ;
126+ // Don't use default swap behavior
127127 evt.preventDefault ();
128+
129+ // Get the response and escape it, then restore the span tags for colors
130+ let content = evt.detail.xhr.responseText ;
131+
132+ // Check if the content has HTML color spans
133+ if (content.includes ('<span')) {
134+ // For colored content, use innerHTML but the pre/code block should preserve whitespace
135+ evt.detail.target.innerHTML = content;
136+ } else {
137+ // For plain text, use textContent to preserve everything exactly
138+ evt.detail.target.textContent = content;
139+ }
128140 }
129141 });
130142 });
138150 <h1>Mermaid ASCII <small style= " font-size: 0.5em; color: #888;" >v{{ .Version }}</small></h1>
139151 <div class= " container" >
140152 <div class= " column" >
141- <form id= " input" hx-post= " /" hx-target= " #result-code" hx-swap= " textContent "
153+ <form id= " input" hx-post= " /" hx-target= " #result-code" hx-swap= " innerHTML "
142154 hx-trigger= " click from:.example-buttons" >
143155 <textarea
144156 name= " mermaid" placeholder= " graph LR"
You can’t perform that action at this time.
0 commit comments