Skip to content

Commit cce4441

Browse files
authored
Merge pull request #1280 from CybotTM/feature/nbsp-text-role
[FEATURE] Add :nbsp: text role for non-breaking spaces
2 parents 6f96acb + b197499 commit cce4441

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

packages/guides-restructured-text/resources/config/guides-restructured-text.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
use phpDocumentor\Guides\RestructuredText\TextRoles\GenericTextRole;
115115
use phpDocumentor\Guides\RestructuredText\TextRoles\LiteralTextRole;
116116
use phpDocumentor\Guides\RestructuredText\TextRoles\MathTextRole;
117+
use phpDocumentor\Guides\RestructuredText\TextRoles\NbspTextRole;
117118
use phpDocumentor\Guides\RestructuredText\TextRoles\ReferenceTextRole;
118119
use phpDocumentor\Guides\RestructuredText\TextRoles\SpanTextRole;
119120
use phpDocumentor\Guides\RestructuredText\TextRoles\TextRole;
@@ -172,6 +173,7 @@
172173
->set(ApiClassTextRole::class)
173174
->set(MathTextRole::class)
174175
->set(LiteralTextRole::class)
176+
->set(NbspTextRole::class)
175177
->set(SpanTextRole::class)
176178

177179
->set(GeneralDirective::class)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link https://phpdoc.org
12+
*/
13+
14+
namespace phpDocumentor\Guides\RestructuredText\TextRoles;
15+
16+
use phpDocumentor\Guides\Nodes\Inline\WhitespaceInlineNode;
17+
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
18+
19+
/**
20+
* Role for inserting a non-breaking space.
21+
*
22+
* Usage: :nbsp:`ignored content`
23+
*
24+
* The content is ignored; the role simply produces a non-breaking space.
25+
* This is an alternative to the ~ syntax (e.g., a~b).
26+
*/
27+
final class NbspTextRole extends BaseTextRole
28+
{
29+
protected string $name = 'nbsp';
30+
31+
public function processNode(
32+
DocumentParserContext $documentParserContext,
33+
string $role,
34+
string $content,
35+
string $rawContent,
36+
): WhitespaceInlineNode {
37+
return new WhitespaceInlineNode();
38+
}
39+
}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
SKIP non-breacking space role does not work
21
<p>This is a non breakable space: a&nbsp;b</p>
32
<p>This is also a non breakable space: a &nbsp; b</p>

0 commit comments

Comments
 (0)