Java 1011, 189 159159 136 bytes
s->c->{var r="";intint p=0,i;forp=0;for(var a:s.split("\\|")){forSystem.out.println(i=p;i-->0;r+="" ");r+=a;for(p+=a.lengthrepeat(p);i++<s+a+" ".repeat(s.replace("|","").length()-p;r+=" "(p+=a.length();r+=c+"\n";}return r;)+1)+c);}
-30 bytes converting Java 7 to Java 10 and optimizing the loops.
-23 bytes converting Java 10 to Java 11, so String#repeat
builtin can be used.
Explanation:
s->c->{ // Method with String & char parameters and Stringno return-type
var r=""; // Result-String, starting empty
int p=0,p=0; // Position-integer, starting at 0
i; for(var a:s.split("\\|")) // Loop over the parts split by "|":
System.out.println( // Index integer
Print with for(vartrailing anewline:s.split("\\|")){//
Loop over the parts split" by".repeat(p) "|"
for(i=p;i-->0;r+=" "); // Add `p` amount of spaces
to the result-String
+a r+=a; // Add plus the current part
to the result-String
" for".repeat(s.replace("|","").length()-(p+=a.length();)+1)
// Add the length of the current part to the position-integer
i++<s.replace("|","").length()-p;r+=" "); // plus the correct trailing amount of spaces
// Add (and add the row'slength trailingof spacesthe current part to the`p` result-Stringat the
r+=c+"\n";} // Add the character and a new-line to the result-String// same time)
return r; +c);} // Return plus the result-Stringcurrent comment character