@@ -72,21 +72,13 @@ protected function request(Collection $blocks)
72
72
$ response = collect ($ response )->keyBy ('id ' );
73
73
74
74
$ blocks ->each (function (Block $ block ) use ($ response ) {
75
- $ blockFromResponse = Arr::get ($ response , "{$ block ->id ()}" , [] );
75
+ $ blockFromResponse = Arr::get ($ response , "{$ block ->id ()}" , $ this -> defaultResponse ( $ block ) );
76
76
77
77
foreach ($ this ->applyDirectlyFromResponse () as $ key ) {
78
78
if (Arr::has ($ blockFromResponse , $ key )) {
79
79
$ block ->{$ key } = $ blockFromResponse [$ key ];
80
80
}
81
81
}
82
-
83
- if (!$ block ->wrapped ) {
84
- $ block ->wrapped = $ this ->defaultWrapped ($ block );
85
- }
86
-
87
- if (!$ block ->highlighted ) {
88
- $ block ->highlighted = $ this ->defaultHighlighted ($ block );
89
- }
90
82
});
91
83
92
84
// Only store the ones we got back from the API.
@@ -221,21 +213,21 @@ protected function setBlocksFromCache(Collection $blocks)
221
213
* In the case where nothing returns from the API, we have to show _something_.
222
214
*
223
215
* @param Block $block
224
- * @return string
225
- */
226
- protected function defaultHighlighted (Block $ block )
227
- {
228
- return htmlentities ($ block ->code );
229
- }
230
-
231
- /**
232
- * In the case where nothing returns from the API, we have to show _something_.
233
- *
234
- * @param Block $block
235
- * @return string
216
+ * @return array
236
217
*/
237
- protected function defaultWrapped (Block $ block )
218
+ protected function defaultResponse (Block $ block )
238
219
{
239
- return "<pre><code class='torchlight'> " . $ this ->defaultHighlighted ($ block ) . '</code></pre> ' ;
220
+ $ lines = array_map (function ($ line ) {
221
+ return "<div class='line'> " . htmlentities ($ line ) . "</div> " ;
222
+ }, explode ("\n" , $ block ->code ));
223
+
224
+ $ highlighted = implode ('' , $ lines );
225
+
226
+ return [
227
+ 'highlighted ' => $ highlighted ,
228
+ 'classes ' => 'torchlight ' ,
229
+ 'styles ' => '' ,
230
+ 'wrapped ' => "<pre><code class='torchlight'> {$ highlighted }</code></pre> " ,
231
+ ];
240
232
}
241
233
}
0 commit comments