Closed clo4 closed 1 year ago
Until String.dedent
is implemented, here's roughly what I'll do:
// If the string is empty, return the input.
// If the string doesn't start with a newline, return the input.
// Otherwise, trim the first line and the last line. Remove the same
// number of characters from the beginning of each line as the number
// of whitespace characters in front of the first line.
function dedent(str: string) {
if (str[0] !== "\n") return str;
const lines = str.split("\n").slice(1, -1);
const margin = lines[0].length - lines[0].trimStart().length;
return lines.map((line) => line.slice(margin)).join("\n");
}
(will benchmark implementations)
Descriptions aren't "dedented" (un-indented) at the moment. There's a proposed
String.dedent
function, could implement this in the help system.This would not apply actively, only when formatting the description for help.