@@ -102,8 +102,8 @@ defmodule ComponentsGuideWeb.ViewSourceLive do
102
102
< . headers_preview headers = { @ state . response . headers } >
103
103
</ . headers_preview >
104
104
<%= if ( @ state . response . body || "" ) != "" do %>
105
- < . html_preview html = { @ state . response . body } >
106
- </ . html_preview >
105
+ < . body_preview content_type = { Fetch.Response . find_header ( @ state . response , "content-type" ) } data = { @ state . response . body } >
106
+ </ . body_preview >
107
107
<% end %>
108
108
<% end %>
109
109
</ output >
@@ -112,6 +112,25 @@ defmodule ComponentsGuideWeb.ViewSourceLive do
112
112
display : none ;
113
113
}
114
114
</ style >
115
+ < script type = "module " >
116
+ const lazyPrismObserver = new IntersectionObserver((entries) => {
117
+ entries . forEach ( entry => {
118
+ if ( entry . isIntersecting && ! entry . target . dataset . highlighted ) {
119
+ entry. target . dataset . highlighted = '1' ;
120
+ window. Prism . highlightAllUnder ( entry . target ) ;
121
+ }
122
+ } ) ;
123
+ } );
124
+ window.customElements.define('lazy-prism', class extends HTMLElement {
125
+ connectedCallback ( ) {
126
+ lazyPrismObserver . observe ( this ) ;
127
+ }
128
+
129
+ disconnectedCallback ( ) {
130
+ lazyPrismObserver . unobserve ( this ) ;
131
+ }
132
+ } )
133
+ </ script >
115
134
"""
116
135
end
117
136
@@ -164,6 +183,20 @@ defmodule ComponentsGuideWeb.ViewSourceLive do
164
183
"""
165
184
end
166
185
186
+ def body_preview ( assigns ) do
187
+ ~H"""
188
+ <%= if @ content_type == "application/json" do %>
189
+ < h2 > JSON</ h2 >
190
+ < lazy-prism >
191
+ < pre class = "text-left " > < code class = "language-json " > <%= @ data %> </ code > </ pre >
192
+ </ lazy-prism >
193
+ <% end %>
194
+ <%= if @ content_type in [ "text/html" , "text/html; charset=utf-8" ] do %>
195
+ < . html_preview html = { @ data } />
196
+ <% end %>
197
+ """
198
+ end
199
+
167
200
def html_preview ( assigns ) do
168
201
~H"""
169
202
<%= for { kind , values } <- list_html_features ( @ html ) do %>
0 commit comments