You are browsing a version that has not yet been released.

Custom Text Roles

An interpreted text role can apply special styles to an inline text.

You can define custom text roles in your project if needed:

Text role class

You can write your own text roles by defining a class that implements Doctrine\RST\TextRoles\TextRole. In most use cases it is more convenient to extend the Doctrine\RST\TextRoles\BaseTextRole.

See TextRole.php for more information.

Example Text Role

1declare(strict_types=1); namespace Doctrine\Tests\RST\TextRoles; use Doctrine\RST\Environment; use Doctrine\RST\Span\SpanToken; use Doctrine\RST\TextRoles\BaseTextRole; class ExampleRole extends BaseTextRole { public function getName(): string { return 'example'; } public function render(Environment $environment, SpanToken $spanToken): string { return '<samp>' . $spanToken->get('text') . '</samp>'; } }
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
⚠️ Unknown reference section "file" in file "custom-text-roles"

Now you can register your text role by registering it in a custom directive factory in your :

1$configuration = new Configuration(); $configuration->addDirectiveFactory(new CustomDirectiveFactory( [], [new ExampleRole()] )); return $configuration;
2
3
4
5
6
7
8