Skip to content

Commit

Permalink
feature: add data-line attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangjchandler committed Oct 14, 2024
1 parent 31fc5aa commit ed9cbd2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Generators/HtmlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ public function generate(array $tokens): string
$lines[] = $this->proxy->line(new Span(
new AttributeList([
'class' => 'line',
'data-line' => $i + 1,
]),
$children,
), $i);
), $i + 1);
}

$code = $this->proxy->code(new Code(children: $lines));
Expand Down
12 changes: 12 additions & 0 deletions tests/Unit/PhikiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ function add(int|float $a, int|float $b): int|float {
expect($html)->not->toContain('language-');
});

it('adds data-line attributes to each line', function () {
$html = (new Phiki)->codeToHtml(<<<'PHP'
function add(int|float $a, int|float $b): int|float {
return $a + $b;
}
PHP, 'php', 'github-dark');

expect($html)->toContain('data-line="1"');
expect($html)->toContain('data-line="2"');
expect($html)->toContain('data-line="3"');
});

it('accepts a grammar enum member', function () {
expect((new Phiki)->codeToTokens('echo $a;', Grammar::Php))->toBeArray();
});
Expand Down

0 comments on commit ed9cbd2

Please sign in to comment.