Skip to content

Commit ac20515

Browse files
Write docs on Decorations
1 parent f2dc705 commit ac20515

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

docs/decorations.mdx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: Decorations
3+
---
4+
5+
Decorations allow you to apply custom classes to specific lines in the generated HTML. This is useful if you want to style certain regions of your code blocks differently, such as focusing attention on specific lines or adding custom colors.
6+
7+
## Usage
8+
9+
To use decorations, you can pass a `LineDecoration` instance to the `PendingHtmlOutput::decoration()` method.
10+
11+
```php
12+
use Phiki\Transformers\Decorations\LineDecoration;
13+
14+
$output = (new Phiki)
15+
->codeToHtml('<?php echo ...', Grammar::Php, Theme::GithubLight)
16+
->decoration(
17+
LineDecoration::forLine(0)->addClass('focus'),
18+
);
19+
```
20+
21+
This will add the `focus` class to the first line of the code block, since lines are zero-indexed.
22+
23+
## Substring decorations
24+
25+
At the time of writing, you can only decorate entire lines.
26+
27+
There are plans to support substring decorations in a future release, which will allow you to apply classes to specific parts of a line. This is quite an involved feature so it may take some time to implement.

docs/docs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
"transformers",
4545
"add-classes-transformer"
4646
]
47-
}
47+
},
48+
"decorations"
4849
]
4950
},
5051
{

0 commit comments

Comments
 (0)