JavaScript ES6, 83 bytes
f=(z,a=[])=>z.replace(/ *0/g,e=>e.replace('0',a.fill(0,l=e.length)[--l]=a[l]+1||1))
This uses an array that holds the current number for each indentation level. Everything past that level is reset to 0 using fill()
.
f=(z,a=[])=>z.replace(/ *0/g,e=>e.replace('0',a.fill(0,l=e.length)[--l]=a[l]+1||1))
This uses an array that holds the current number for each indentation level. Everything past that level is reset to 0 using fill()
.