Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 16362a9

Browse files
authored
fix for period inside parens (#36)
1 parent 60ae5a1 commit 16362a9

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

docs/class.Facebook.HHAPIDoc.DocBlock.DocBlock.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@
4343
</head>
4444
<body>
4545
<h1>Facebook\HHAPIDoc\DocBlock\DocBlock</h1>
46-
<p>Class to represent and parse a docblock (a</p>
47-
<p>k.a. doc comment).</p>
46+
<p>Class to represent and parse a docblock (a.k.a. doc comment)</p>
4847
<p>These comments always are delimeted by <code>/**</code> and <code>*\/</code>.</p>
4948
<p>DocBlocks are treated as GitHub Flavored Markdown, and standard
5049
JavaDoc style tags are supported, such as <code>@param</code>, <code>@see</code>, and

src/DocBlock/DocBlock.hack

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,21 @@ final class DocBlock {
6565

6666
$content = Str\trim_left(Str\join($content_lines, "\n"));
6767

68-
$first_period = Str\search($content, '.');
68+
// Find first period that is not nested e.g. inside a link's URL.
69+
$first_period = null;
70+
$nesting_level = 0;
71+
for ($i = 0; $i < Str\length($content); ++$i) {
72+
if ($content[$i] === '.' && $nesting_level === 0) {
73+
$first_period = $i;
74+
break;
75+
} else if ($content[$i] === '(' || $content[$i] === '[') {
76+
++$nesting_level;
77+
} else if ($content[$i] === ')' || $content[$i] === ']') {
78+
// Trim at 0 in case the docblock is not correctly parenthesized.
79+
$nesting_level = Math\maxva($nesting_level - 1, 0);
80+
}
81+
}
82+
6983
if ($first_period !== null) {
7084
// Handle '...'
7185
$slice = Str\slice($content, $first_period);

0 commit comments

Comments
 (0)