Skip to content

Commit b94ce40

Browse files
committed
Updated rewrites for Ruff! output.
1 parent d59b669 commit b94ce40

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

doc/build.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,65 @@ EOF
256256

257257
test $VERBOSE -eq 1 && printf -- " ${ANSI_LIGHT_CYAN}Fix seealso directive${ANSI_NOCOLOR}\n"
258258
sed -i '/^\.\. seealso::/,/^\.\. index::/ s/^- / - /' "${rstFile}"
259+
260+
test $VERBOSE -eq 1 && printf -- " ${ANSI_LIGHT_CYAN}Move return value up${ANSI_NOCOLOR}\n"
261+
awk -i inplace '
262+
function flush_buffers() {
263+
# If we have a Return Value block, print it first
264+
if (return_buf != "") {
265+
printf "%s", return_buf;
266+
}
267+
# Then print the Description/Seealso/Middle block
268+
if (desc_buf != "") {
269+
printf "%s", desc_buf;
270+
}
271+
desc_buf = ""; return_buf = "";
272+
in_desc = 0; in_return = 0;
273+
}
274+
275+
# 1. Detect the start of the Description block
276+
/^.. rubric:: Description/ {
277+
flush_buffers(); # Safety flush in case of back-to-back procedures
278+
in_desc = 1;
279+
desc_buf = $0 ORS;
280+
next;
281+
}
282+
283+
# 2. Detect the start of the Return value block
284+
/^.. rubric:: Return value/ {
285+
if (in_desc) {
286+
in_desc = 0;
287+
in_return = 1;
288+
return_buf = $0 ORS;
289+
next;
290+
}
291+
print; # If found outside a description context, print normally
292+
next;
293+
}
294+
295+
# 3. Detect the end of the procedure (the index)
296+
/^.. index::/ {
297+
if (in_return) {
298+
flush_buffers();
299+
} else if (in_desc) {
300+
# If we reached index without finding a Return Value
301+
printf "%s", desc_buf;
302+
desc_buf = "";
303+
in_desc = 0;
304+
}
305+
print;
306+
next;
307+
}
308+
309+
# 4. Collection Logic
310+
in_desc { desc_buf = desc_buf $0 ORS; next }
311+
in_return { return_buf = return_buf $0 ORS; next }
312+
313+
# 5. Default Print
314+
{ print }
315+
316+
END { flush_buffers() }
317+
' "${rstFile}"
259318
done
260319
else
261320
printf -- "${ANSI_MAGENTA}[BUILD] Patch ReST files ... ${ANSI_YELLOW}[SKIPPED]\n${ANSI_NOCOLOR}"

0 commit comments

Comments
 (0)