Skip to content

Commit 044ebd6

Browse files
committed
Added escape sequences that allow "literal" inline tags in descriptions.
1 parent e0a5a75 commit 044ebd6

File tree

2 files changed

+93
-11
lines changed

2 files changed

+93
-11
lines changed

src/phpDocumentor/Reflection/DocBlock/LongDescription.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,14 @@ public function getParsedContents()
7171
# Match nested inline tags.
7272
# Because we did not catch the tag delimiters
7373
# earlier, we must be explicit with them here.
74+
# Notice that this also matches "{}", as a way to
75+
# later introduce it as an escape sequence.
7476
\{(?1)?\}
7577
|
7678
# "{@}" is not a valid inline tag. This ensures that
7779
# having it occur inside an inline tag does not trip
78-
# us up.
80+
# us up. While this is required in any event, notice
81+
# that this is also later an escape sequence.
7982
\{\@\}
8083
|
8184
# If we are not dealing with a nested inline tag,
@@ -98,6 +101,17 @@ public function getParsedContents()
98101
$this->parsedContents[$i]
99102
);
100103
}
104+
105+
//In order to allow "literal" inline tags, the otherwise invalid
106+
//sequence "{@}" is changed to "@", and "{}" is changed to "}".
107+
//See unit tests for examples.
108+
for ($i=0, $l = count($this->parsedContents); $i<$l; $i += 2) {
109+
$this->parsedContents[$i] = str_replace(
110+
array('{@}', '{}'),
111+
array('@', '}'),
112+
$this->parsedContents[$i]
113+
);
114+
}
101115
}
102116
return $this->parsedContents;
103117
}

tests/phpDocumentor/Reflection/DocBlock/LongDescriptionTest.php

Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,21 @@ public function testNestedInlineTagParsing()
103103
$parsedContents[1]
104104
);
105105
$this->assertSame('.', $parsedContents[2]);
106+
107+
$parsedDescription = $parsedContents[1]->getParsedDescription();
108+
$this->assertCount(3, $parsedDescription);
109+
$this->assertSame("inline tag with\n", $parsedDescription[0]);
110+
$this->assertInstanceOf(
111+
__NAMESPACE__ . '\Tag\LinkTag',
112+
$parsedDescription[1]
113+
);
114+
$this->assertSame(' in it', $parsedDescription[2]);
106115
}
107-
108-
public function testEmptyInlineTag()
116+
117+
public function testLiteralOpeningDelimiter()
109118
{
110119
$fixture = <<<LONGDESC
111-
This is text for a description with an empty inline tag - {@}.
120+
This is text for a description containing { that is literal.
112121
LONGDESC;
113122
$object = new LongDescription($fixture);
114123
$this->assertSame($fixture, $object->getContents());
@@ -118,29 +127,35 @@ public function testEmptyInlineTag()
118127
$this->assertSame($fixture, $parsedContents[0]);
119128
}
120129

121-
public function testNestedEmptyInlineTag()
130+
public function testNestedLiteralOpeningDelimiter()
122131
{
123132
$fixture = <<<LONGDESC
124-
This is text for a description with an {@internal inline tag with an empty
125-
inline tag - {@} in it}.
133+
This is text for a description containing {@internal inline tag that has { that
134+
is literal}.
126135
LONGDESC;
127136
$object = new LongDescription($fixture);
128137
$this->assertSame($fixture, $object->getContents());
129138

130139
$parsedContents = $object->getParsedContents();
131140
$this->assertCount(3, $parsedContents);
132141
$this->assertSame(
133-
'This is text for a description with an ',
142+
'This is text for a description containing ',
134143
$parsedContents[0]
135144
);
136145
$this->assertInstanceOf(
137146
__NAMESPACE__ . '\Tag',
138147
$parsedContents[1]
139148
);
140149
$this->assertSame('.', $parsedContents[2]);
150+
151+
$this->assertSame(
152+
array('inline tag that has { that
153+
is literal'),
154+
$parsedContents[1]->getParsedDescription()
155+
);
141156
}
142157

143-
public function testInlineTagDelimiters()
158+
public function testLiteralClosingDelimiter()
144159
{
145160
$fixture = <<<LONGDESC
146161
This is text for a description with {} that is not a tag.
@@ -150,10 +165,13 @@ public function testInlineTagDelimiters()
150165

151166
$parsedContents = $object->getParsedContents();
152167
$this->assertCount(1, $parsedContents);
153-
$this->assertSame($fixture, $parsedContents[0]);
168+
$this->assertSame(
169+
'This is text for a description with } that is not a tag.',
170+
$parsedContents[0]
171+
);
154172
}
155173

156-
public function testNestedInlineTagDelimiters()
174+
public function testNestedLiteralClosingDelimiter()
157175
{
158176
$fixture = <<<LONGDESC
159177
This is text for a description with {@internal inline tag with {} that is not an
@@ -173,5 +191,55 @@ public function testNestedInlineTagDelimiters()
173191
$parsedContents[1]
174192
);
175193
$this->assertSame('.', $parsedContents[2]);
194+
195+
$this->assertSame(
196+
array('inline tag with } that is not an
197+
inline tag'),
198+
$parsedContents[1]->getParsedDescription()
199+
);
200+
}
201+
202+
public function testInlineTagEscapingSequence()
203+
{
204+
$fixture = <<<LONGDESC
205+
This is text for a description with literal {{@}link}.
206+
LONGDESC;
207+
$object = new LongDescription($fixture);
208+
$this->assertSame($fixture, $object->getContents());
209+
210+
$parsedContents = $object->getParsedContents();
211+
$this->assertCount(1, $parsedContents);
212+
$this->assertSame(
213+
'This is text for a description with literal {@link}.',
214+
$parsedContents[0]
215+
);
216+
}
217+
218+
public function testNestedInlineTagEscapingSequence()
219+
{
220+
$fixture = <<<LONGDESC
221+
This is text for a description with an {@internal inline tag with literal
222+
{{@}link{} in it}.
223+
LONGDESC;
224+
$object = new LongDescription($fixture);
225+
$this->assertSame($fixture, $object->getContents());
226+
227+
$parsedContents = $object->getParsedContents();
228+
$this->assertCount(3, $parsedContents);
229+
$this->assertSame(
230+
'This is text for a description with an ',
231+
$parsedContents[0]
232+
);
233+
$this->assertInstanceOf(
234+
__NAMESPACE__ . '\Tag',
235+
$parsedContents[1]
236+
);
237+
$this->assertSame('.', $parsedContents[2]);
238+
239+
$this->assertSame(
240+
array('inline tag with literal
241+
{@link} in it'),
242+
$parsedContents[1]->getParsedDescription()
243+
);
176244
}
177245
}

0 commit comments

Comments
 (0)