We’re rewarding the question askers & reputations are being recalculated! Read more.
3 of 3 fix framework after Retina's version was fixed on TIO

Retina, 52 bytes

This answer is based on my Perl answer, with the help of Martin Ender for the golfing with Retina.

^ *
[
$
]
\s+
, 
m):`.+
[$&]
*T`[]`{}
], .
; 
^.|]$

Try it online!

The explanations can be found on my Perl answer. The differences are:

*
[
$
]

Instead of s/^ *(.+)/[$1]/gm to both remove the leading spaces and add brackets around the lines.

^.|]$

To remove the leading and trailing brackets for the third output.