Skip to content

Commit

Permalink
Be smarter about {@link...} tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
danfuzz committed May 7, 2024
1 parent 47d6736 commit d1daf06
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions scripts/lib/bashy-node/node-project/reflow-jsdoc
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function calcIndent(firstIndent, _locals_, result) {
}
# Emit one paragraph of comment.
function autoflowLines(_locals_, curIndent, i, line, text) {
function autoflowLines(_locals_, curIndent, i, line, maxLength, text) {
if (count == 0) return;
text = "";
Expand All @@ -129,31 +129,40 @@ function autoflowLines(_locals_, curIndent, i, line, text) {
while (text != "") {
if (length(text) + length(curIndent) <= 80) {
i = length(text);
line = text;
text = "";
} else {
for (i = 81 - length(curIndent); i > 0; i--) {
if (substr(text, i, 1) == " ") break;
}
if (i == 0) {
# Very long word. Just emit it on its own line.
match(text, /^[^ ]+/);
i = RLENGTH;
line = "";
maxLength = 80 - length(curIndent);
for (;;) {
i = firstWordLength(text);
# `line != ""` is to let a very long word just have its own line.
if ((line != "") && ((i + 1 + length(line)) > maxLength)) {
break;
}
if (line != "") line = line " ";
line = line substr(text, 1, i);
text = substr(text, i + 1);
sub(/^ /, "", text);
}
}
line = substr(text, 1, i);
sub(/^ */, "", line);
sub(/ *$/, "", line);
print curIndent line;
curIndent = indent;
text = substr(text, i + 1);
}
count = 0;
indent = "";
firstIndent = "";
}
# Get the length of the first word of the given string.
function firstWordLength(str, _locals_, got) {
# Note: Because of a JSDoc deficiency, `{@link` has to be on the same line as
# the next word in order to be recognized.
got = match(str, /^[^ ]+|\{@link [^\}]+\}[^ ]*/);
return (got == 0) ? 0 : RLENGTH;
}
'

# Processes a single file.
Expand Down

0 comments on commit d1daf06

Please sign in to comment.