Skip to content

Commit

Permalink
Get block tags to be reflowed. Clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
danfuzz committed Mar 28, 2024
1 parent d6dc66b commit 3c3470f
Showing 1 changed file with 25 additions and 31 deletions.
56 changes: 25 additions & 31 deletions scripts/lib/bashy-node/node-project/reflow-jsdoc
Original file line number Diff line number Diff line change
Expand Up @@ -52,70 +52,64 @@ inCodeQuote {
next;
}
# Paragraph separator.
inDoc && /^ *[*]$/ {
autoflowLines();
print;
next;
}
# Start of a tag. (Should be handled, but not yet implemented.)
inDoc && /^ *[*] *@/ {
# End of doc comment block.
inDoc && /^ *[*]\/$/ {
autoflowLines();
inDoc = 0;
}
# End of doc comment block.
inDoc && /^ *[*]\/$/ {
# Paragraph separator.
inDoc && /^ *[*]$/ {
autoflowLines();
inDoc = 0;
print;
next;
}
# Additional line in current paragraph, or possibly start of new paragraph (if
# indentation changes; not perfect but good enough for a follow-on human pass).
# Additional line in current paragraph, or start of new paragraph (if
# indentation changes).
inDoc {
if (indent == "") {
indent = $0;
match(indent, /^[ *]* /);
firstIndent = substr(indent, RSTART, RLENGTH);
thisIndent = matchIndent($0);
if ((indent == "") || (indent != thisIndent)) {
autoflowLines();
firstIndent = thisIndent;
indent = calcIndent(firstIndent);
indentLength = length(firstIndent);
} else {
newIndent = $0;
match(newIndent, /^[ *]* /);
newIndent = substr(newIndent, RSTART, RLENGTH);
if (indent != newIndent) {
autoflowLines();
firstIndent = newIndent;
indent = calcIndent(firstIndent);
}
# Expected the-rest-indent.
indentLength = length(indent);
}
lines[count] = $0;
lines[count] = substr($0, indentLength + 1);
count++;
next;
}
{ print; }
# Matches any of the allowed "indent" patterns (which also includes `@tag`s for
# block tags).
function matchIndent(line) {
match(line, /^ *[*] ([ *]*|@[a-zA-Z]+ +)/);
return substr(line, RSTART, RLENGTH);
}
# Convert a first-indent into a the-rest-indent.
function calcIndent(firstIndent, _locals_, result) {
result = firstIndent;
match(result, /^ *[*] /);
result = substr(result, RSTART, RLENGTH);
while (length(result) < length(firstIndent)) result = result " ";
#print "FIRST <" firstIndent "> REST <" result ">";
return result;
}
# Emit one paragraph of comment.
function autoflowLines(_locals_, curIndent, i, line, text) {
if (count == 0) return;
#print "INDENTS: <" firstIndent "> <" indent ">";
text = "";
for (i = 0; i < count; i++) {
line = lines[i];
sub(/^[ *]* /, "", line);
sub(/^ */, "", line);
if (i == 0) text = line;
else text = text " " line;
}
Expand Down

0 comments on commit 3c3470f

Please sign in to comment.