Retina, 47 bytes
^|\\
$&
+m`^( *)( /|\\)(/| \\)
$1$2¶$1$3
m`^
Try it online! Link includes test cases. Explanation:
^|\\
$&
Add a space at the beginning of each line and before each \
.
+m`^( *)( /|\\)(/| \\)
$1$2¶$1$3
Consider the first two characters of the string. If the first is a /
then the indent needs to be decremented; this is achieved by including the preceding space in the capture (which always exists because the first stage added it); if the second is a \\
then it needs to be incremented; this is achieved by including the space that the first stage added in the capture. Having given the second character the correct indent, the stage is repeated for the second and third character etc.
m`^
Remove the extra indent.
I've written a 94-byte version which (like my Charcoal answer) allows any combination of slashes: Try it online! Explanation:
.$
¶$.`$* $&
Get the ball rolling by taking the last slash and indenting it to the same position on its own line.
/
/
Prefix spaces to all forward slashes so that they can be captured.
+`^(.*)( /|\\)¶( *)( \\|/)
$1¶$3$2¶$3$4
Repeatedly take the last slash of the input and align it on its own line with the slash on the line below.
+ms`^(?<!^[\\/].*) (?!.*^[\\/])
Delete any left-over indentation.
G`.
Delete the now empty input.