File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33## Unreleased
44
5+ ## 0.5.1 - 2021-09-06
6+
7+ ### Changed
8+ - When loading content from files using the ` <<< path/to/file.php ` convention, you can now wrap it in a comment e.g. ` // <<<path/to.file.php ` .
9+
510## 0.5.0 - 2021-09-06
611
712### Changed
Original file line number Diff line number Diff line change @@ -147,7 +147,7 @@ protected function getContent($node)
147147 $ content = $ this ->getLiteralContent ($ node );
148148
149149 // Check for our file loading convention.
150- if (!Str::startsWith ($ content , '<<< ' )) {
150+ if (!Str::contains ($ content , '<<< ' )) {
151151 return $ content ;
152152 }
153153
@@ -158,6 +158,9 @@ protected function getContent($node)
158158 return $ content ;
159159 }
160160
161+ // Blow off the end of comments that require closing tags, e.g. <!-- -->
162+ $ file = head (explode (' ' , $ file ));
163+
161164 return Torchlight::processFileContents ($ file ) ?: $ content ;
162165 }
163166
Original file line number Diff line number Diff line change @@ -140,6 +140,52 @@ public function can_load_file()
140140 });
141141 }
142142
143+ /** @test */
144+ public function can_load_file_with_comment ()
145+ {
146+ config ()->set ('torchlight.snippet_directories ' , [
147+ __DIR__
148+ ]);
149+
150+ $ markdown = <<<'EOT'
151+ ```
152+ // <<< Support/file1.php
153+ ```
154+ EOT;
155+
156+ Http::fake ();
157+
158+ $ this ->render ($ markdown );
159+
160+ Http::assertSent (function ($ request ) {
161+ return $ request ['blocks ' ][0 ]['code ' ] === '// this is file 1 ' ;
162+ });
163+ }
164+
165+
166+ /** @test */
167+ public function can_load_file_with_two_part_comment ()
168+ {
169+ config ()->set ('torchlight.snippet_directories ' , [
170+ __DIR__
171+ ]);
172+
173+ $ markdown = <<<'EOT'
174+ ```
175+ <!-- <<< Support/file1.php -->
176+ ```
177+ EOT;
178+
179+ Http::fake ();
180+
181+ $ this ->render ($ markdown );
182+
183+ Http::assertSent (function ($ request ) {
184+ return $ request ['blocks ' ][0 ]['code ' ] === '// this is file 1 ' ;
185+ });
186+ }
187+
188+
143189 /** @test */
144190 public function non_existent_file_just_stays ()
145191 {
You can’t perform that action at this time.
0 commit comments