This definition uses string:tokens to split the string argument on newliness, then uses lists:flatmap to process each line, removing any existing leading space, prepending the proper indentation to the start of each line, and appending the newline (lost during the tokenization step).
-- BrentAFulgham - 21 Aug 2004