Skip to content

Commit 6c9ccc4

Browse files
committed
Allow tab replacement to be opt out
1 parent ef49916 commit 6c9ccc4

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

config/torchlight.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
// The Host of the API.
2020
'host' => env('TORCHLIGHT_HOST', 'https://api.torchlight.dev'),
2121

22+
// We replace tabs in your code blocks with spaces in HTML. Set
23+
// the number of spaces you'd like to use per tab. Set to
24+
// `false` to leave literal tabs in the HTML.
25+
'tab_width' => 4,
26+
2227
// Global options to control blocks-level settings.
2328
// https://torchlight.dev/docs/options
2429
'options' => [

src/Block.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,11 @@ protected function clean($code)
214214
*/
215215
protected function replaceTabs($code)
216216
{
217-
$multiplier = Torchlight::config('spaces_per_tab', 4);
217+
$multiplier = Torchlight::config('tab_width', 4);
218+
219+
if ($multiplier === false) {
220+
return $code;
221+
}
218222

219223
return str_replace("\t", str_repeat(' ', $multiplier), $code);
220224
}

tests/BlockTest.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function it_replaces_tabs()
5656
public function can_change_tab_size()
5757
{
5858
Torchlight::getConfigUsing([
59-
'spaces_per_tab' => 2
59+
'tab_width' => 2
6060
]);
6161

6262
$block = Block::make();
@@ -74,6 +74,23 @@ public function can_change_tab_size()
7474
$this->assertEquals($block->code, $cleaned);
7575
}
7676

77+
78+
/** @test */
79+
public function can_leave_tabs_in()
80+
{
81+
Torchlight::getConfigUsing([
82+
'tab_width' => false
83+
]);
84+
85+
$block = Block::make();
86+
87+
$block->code("if (1) {\n\tif (1) {\n\t\treturn;\n\t}\n}");
88+
89+
$cleaned = "if (1) {\n\tif (1) {\n\t\treturn;\n\t}\n}";
90+
91+
$this->assertEquals($block->code, $cleaned);
92+
}
93+
7794
/** @test */
7895
public function it_right_trims()
7996
{

0 commit comments

Comments
 (0)