Skip to main content
1 of 4

C (gcc), 96 bytes

i;p;j;main(c){for(;~(c=getchar());printf("%c\n",p=c))for(j=c-p?i:c-47?++i:--i;j--;)printf(" ");}

Try it online!

Ungolfed

i;
p;
j;

main(c)
{
    for (; ~(c = getchar()); printf("%c\n", p = c))
        for (j = c - p ? i : c - 47 ? ++i : --i; j--;)
            printf(" ");
}

Explanation

i (indentation), p (previous), j (loop variable for printing spaces) and c (character) are all integers initialised to 0

Get a character from stdin and store it in c. Break if it's EOF (-1)

If c and p are different, i stays the same. If c and p are the same, increment i if c is a backslash and decrement i if c is a forward slash

j = i

Print j spaces

p = c

Print c and a newline

Get another character from stdin