Skip to content

Commit 011a832

Browse files
Fix focus class not being added to pre element in CommonMark adapter (#108)
1 parent 5506915 commit 011a832

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

docs/commonmark.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ pre.phiki code .line.highlight {
8989
background-color: hsl(197, 88%, 94%);
9090
}
9191

92-
.shiki.focus .line:not(.focus) {
92+
pre.phiki.focus .line:not(.focus) {
9393
transition: all 250ms;
9494
filter: blur(2px);
9595
}
9696

97-
.shiki.focus:hover .line {
97+
pre.phiki.focus:hover .line {
9898
transition: all 250ms;
9999
filter: blur(0);
100100
}

src/Adapters/CommonMark/Transformers/MetaTransformer.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ public function preprocess(string $code): string
1919
return $code;
2020
}
2121

22+
public function pre(Element $pre): Element
23+
{
24+
if ($this->focuses !== []) {
25+
$pre->properties->get('class')->add('focus');
26+
}
27+
28+
return $pre;
29+
}
30+
2231
public function line(Element $span, array $tokens, int $index): Element
2332
{
2433
if (in_array($index + 1, $this->highlights, true)) {

tests/Adapters/CommonMark/Transformers/MetaTransformerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ function b() {}
5454
```
5555
MD);
5656

57-
expect($output)->toContain('<span class="line focus">');
57+
58+
expect($output)->toContain('<pre class="phiki language-php github-light focus"')->toContain('<span class="line focus">');
5859
});
5960

6061
it('can focus a range of lines', function () {

0 commit comments

Comments
 (0)