[Question]
  [
[Stack Exchange doesn't know how to transpose tables.](https://meta.stackexchange.com/a/357504/317948) Let's help.
**Given a markdown table, transpose it.**
Input assumptions:
* There will be at least two rows (including header) and two columns
* Either all cells have no leading space or all cells have exactly one leading space (you must handle both)
* If the cells have a leading space, then the widest cell in every column has exactly one trailing space, otherwise, the widest cell in every column has no trailing spaces
* All pipes line up
* The header-body separator lines of dashes extend the full width of their column, except a leading and tailing space if the table uses this
* Cell alignment (`-:`, `:-:`, etc.) is not used
* No other extraneous spaces appear (this includes between words)
* Either all rows have a trailing pipe or no rows have a trailing pipe (you must handle both)
* Cells contain only printable ASCII, but no pipes (`|`), dashes (`-`) or any characters that need special treatment (`\`, `**`, etc.)
* All cells will have at least *some* non-space content
Output requirements:
* Trailing pipe on every row or no trailing pipes (must be consist for any one result)
* Either no leading spaces, or exactly one leading space in every cell (must be consist for any one result)
* If you produce leading spaces, then the widest cell in each column must have exactly one trailing space
* All pipes must line up
* The header-body separator must extend to the full width of the column, save for leading and trailing spaces, if used in that result
* Trailing spaces (and up to one trailing line break) are acceptable
# Test cases
## A
### Test inputs (you must handle every one of these)
```
| A header | Another header |
| -------- | -------------- |
| First    | row            |
| Second   | row            |
```
```
| A header | Another header
| -------- | --------------
| First    | row           
| Second   | row            
```
```
|A header|Another header|
|--------|--------------|
|First   |row           |
|Second  |row           |        
```
```
|A header|Another header
|--------|--------------
|First   |row           
|Second  |row           
```
### For any of the above inputs, output must be any one of the below (not necessarily corresponding 1:1)
```
| A header       | First | Second |
| -------------- | ----- | ------ |
| Another header | row   | row    |
```
```
| A header       | First | Second
| -------------- | ----- | ------
| Another header | row   | row   
```
```
|A header      |First|Second|
|--------------|-----|------|
|Another header|row  |row   |
```
```
|A header      |First|Second
|--------------|-----|------
|Another header|row  |row   
```
## B
### Test inputs (you must handle every one of these)
```
| A header | Another header | Last column here  |
| -------- | -------------- | ----------------- |
| First    | 0              | more content here |
| Second   | row            | that's it!        |
```
```
| A header | Another header | Last column here 
| -------- | -------------- | -----------------
| First    | 0              | more content here
| Second   | row            | that's it!       
```
```
|A header|Another header|Last column here |
|--------|--------------|-----------------|
|First   |0             |more content here|
|Second  |row           |that's it!       |
```
```
|A header|Another header|Last column here
|--------|--------------|-----------------
|First   |0             |more content here
|Second  |row           |that's it!
```
### For any of the above inputs, output must be any one of the below (not necessarily corresponding 1:1)
```
| A header         | First             | Second     |
| ---------------- | ----------------- | ---------- |
| Another header   | 0                 | row        |
| Last column here | more content here | that's it! |
```
```
| A header         | First             | Second    
| ---------------- | ----------------- | ----------
| Another header   | 0                 | row       
| Last column here | more content here | that's it!
```
```
|A header        |First            |Second    |
|----------------|-----------------|----------|
|Another header  |0                |row       |
|Last column here|more content here|that's it!|
```
```
|A header        |First            |Second    
|----------------|-----------------|----------
|Another header  |0                |row       
|Last column here|more content here|that's it!
```
  
[Answer]
# [Python 3.8 (pre-release)](https://docs.python.org/3.8/), 218 bytes
```
n=[(t:=[x for s in l.split('|')if(x:=s.strip())],max(map(len,t)))for l in open(0)]
del n[1]
j=''.join
f=lambda c:j(f'|{l[c]:{w}}'for l,w in n)
print(f(0),j('|'+w*'-'for _,w in n),*map(f,range(1,len(n[0][0]))),sep='\n')
```
[Try it online!](https://tio.run/##VY5Ba8QgFITv/gpv6taEXXopAQ972T/QYxqKTbQxmKeokJR1f3tqUgrt8JjTfPPGf6XRwfOLD9sGoqWpEe2KtQs4YgPY1tFbkyjJhBlN10bEOqZgPGWs47Nc6Sw9tQp4YoztmN0x5xXQM@vQoCyG9tKhSRBST84A0sLK@WOQuG8mqkm@27bvmvvyeJCD58veAAz5YCBRXXr4tA94Wk6kOjLvvxl@2t9rHiR8KnrhZQiF9tyVK3N4VF6QNyBs2/IVj0oOKuBD@WZCTPlV9Q4GlKt/yn@8QvkKLo0F/OFzcEvhD8foGw "Python 3.8 (pre-release) – Try It Online")
-12 bytes thanks to basic code golfing advice by @cairdcoinheringaahing :)
-25 bytes thanks to @ovs by using `open(0)` instead of `sys.stdin`!
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), ~~84~~ ~~73~~ ~~67~~ 59 bytes
-6 bytes from @rak1507's trim implementation (`2(|(&\^:)_)/`)
-19 bytes from golfing
```
{,'/("|",'++?[;1;"-"]{(|/#'x)$x^,""}2(|(&\^:)_)/'"|"\)'x_1}
```
[Try it online!](https://ngn.bitbucket.io/k/#eJyVk71ugzAUhXc/xa1b1bZCRPiZ8FDZQ6duHZsmRQkRkRqQiKsixXn3GlLUOCBT7mTdA/7OEYddcvKIT7HGHpnNnt54wPEcv5+o9u9JzR7qlYfxOaSaPi5XCVszn5hnl4zU6+CMkAgS8y4IyLN0m1VgjkWpcnPqFpgbff478HfsFq3+vK+OCsxoqMpvuJqL/pptymI7rDMkQrcJtwW3gRE8ZhyJqMF3dG2zW/8dStvkVuvI2r651TrurQZN6NhBdUAdTAfSABGSox8bXlJz8ab8/DoUZlllMF6Am8VgKRZgjYZDae42TlVWqAtotCig8lSRI+zV3XV55Eh5hkJNjzQ90PQ4TRhnFXs5nOXsZbDraifQPf/OAve8t1/C1eie+UnWJzn/n/Hmj/iAReL5dEeoCLgIuYi4iLkMuAy5jLiMGfMIXhYY/QC3xGYe)
Takes a list of strings, one for each row. Returns a list of strings, without leading/trailing spaces, and without trailing pipes.
* `x_1` drop the row at index 1 (i.e., the one with all the `-`'s)
* `(...)'` run the code in parenthesis on each row of the input
	+ `"|"\` split each row on pipes (i.e. get the cells)
	+ `2(|(&\^:)_)/'` strip leading and trailing whitespace from each cell's contents
	+ `{...x^,""}` remove empty cells
	+ `{(|/#'x)$x...}` pad the cells (of each row) with spaces so they are all the same length
	+ `?[;1;"-"]` insert a cell containing the character `"-"` in the proper place
	+ `++` transpose each row to generate the correct number of `"-"`s, then transpose back
	+ `"|",'` prepend a `"|"` to each cell
* `,'/` concatenate the result by column
[Answer]
# [Ruby 2.7](https://www.ruby-lang.org/), 144 bytes
```
->a{(a=(a.map{_1.scan /\| ?\K[^|
]*[^| 
-]/}-[[]]).map{|l|l.map{_1.ljust l.map(&:size).max}}.transpose.map{?|+_1*?|}).insert 1,a[0].tr("^|",?-)}
```
[Try it online!](https://tio.run/##pZJNT8MwDIbv/RWmB@jG2o0r0qi4cIEbx66TwpZpRV06Jan4mPvbi1foRlalIsOHynplx@9TW5YvH/VqWod3bBewacCiDdvuMMc8UgsmYDxDiGePyRy9dEhf8MJ0XIVJkqaDY2mTKFRR/loqDY0QXN6q7JPvq96rKtKSCbUtFG@7YrzOhzFWgygTiksNNyOWTFIqDPw5@qM4HFT1ttQKVomPcA9rzpZcAqWi0GvKDsITo6GLIi83gkTJAdBDCH8CjqlFaDTqeMgkPUSBMAEjEDYFvbsohOZCfw/ZdzxzkpZNgSzezA69ZvpKQaYvDpof5ZngKvX2XJ53Jp0rmyuZK5eNqoVCEwk7QPQnW69oWscODNW2MGiiYAeEalsQNDGwA4H/pXBgcED4C8E5V9V/Q@bFnF5A/324u@nz0uek14frOu3r@7WtkxXYl3OmC6sJqwerBWNy/QU "Ruby – Try It Online")
Takes in an array of lines, and outputs array of lines through the last output format. TIO uses an older version of Ruby, whereas in Ruby 2.7, we've numbered parameters, which saves *six* bytes!
[Answer]
# JavaScript (ES8), 204 bytes
Expects and returns an array of lines. Uses the last output format.
```
s=>(m=[,0]).map((r,y)=>m[r&&y].map((s,x)=>(r?s:"").padEnd(w[x],"-"[r])).join`|`,s.map(w=(s,y)=>s.replace(/\| *(.+?) *(?=\||$)/g,(_,s)=>((v=s.length)<w[y]?0:w[y]=v,m[x+=x==1]=m[x++]||[])[y]=s,y+=y<2,x=0)))
```
[Try it online!](https://tio.run/##tZGxbsIwEIZ3nsK1Kmo3JtCOCIM6tFO3jsEqETEkKLEj24Ug3btTBxqqNOoAVW@502//d/7Om3gb26XJSjdQOpGHFT9YPiUFj9hI0LCIS0IM21M@LSLT7@/FSbKs8hIxMzvGmIZlnDyrhOyiSjA8wJERlIYbnakFLJg9Wnbcm@o@NjSyzOOlJMM5oHsSBjPq04zPAW7pcM3IO7N1c7LlNsylWruUTnbRXsxG4zrxLSuiKuAV5w@C12UgACJB6zM/I@D7ySOr@IhSelhqZXUuw1yvyYpEPYQwoCeUyjiRBvlSaZf66iy8xtahpc4/CuVFIxECzE62wVeg7/IX4ag1tpfM@JY@AI1QKwAV2k/wb3RSudO4s@1Nej053jJ617a5NHZ3FmXu5qzhnjitnOC5whQF6Jh7f1/AVfhXwV@Ffgl4ww1taugwN7/Q4ECbDjq8jaHhhTYtdFgbQ8MKbVLocMK/gF7KeSnmpZQ/IOnhEw "JavaScript (Node.js) – Try It Online")
## Commented
### Step 1
Extracting the content of all cells and saving them into the matrix `m[]`.
```
s.map(w =                   // w is an object used to store the max. width in each row
  (s, y) =>                 // for each string s at position y in the input array:
  s.replace(                //   match in s all occurrences of:
    /\| *(.+?) *(?=\||$)/g, //     "\|"       a pipe
                            //     " *"       followed by optional whitespace
                            //     "(.+?)"    followed by a non-greedy string
                            //                (this is the payload)
                            //     " *"       followed by optional whitespace
                            //     "(?=\||$)" followed by either a pipe or the end of
                            //                the line (not captured)
    (_, s) =>               //     for each payload string s found in there:
      ( (v = s.length)      //       define v as the length of this string
        < w[y] ?            //       if it's smaller than w[y]:
          0                 //         do nothing
        :                   //       else:
          w[y] = v,         //         update w[y] to v
        m[x += x == 1] =    //       increment x if x = 1
          m[x++] || []      //       if undefined, initialize m[x] to an empty array
                            //       increment x afterwards
      )[y] = s,             //       save s in m[x][y]
                            //     initialization:
    y += y < 2,             //       increment y if y = 0 or y = 1
    x = 0                   //       start with x = 0
  )                         //   end of replace()
)                           // end of map()
```
### Step 2
Building the output.
```
(m = [, 0])      // initialize m[] with m[1] = 0 (reserved for the separator lines)
                 // (this is actually done before step 1)
.map((r, y) =>   // for each row r[] at position y in m[]:
  m[r && y]      //   use m[0] if r = 0, or m[y] otherwise
  .map((s, x) => //   for each string s at position x in this row:
    (r ? s : "") //     use an empty string if r = 0, or s otherwise
    .padEnd(     //     pad it with:
      w[x],      //       w[x] characters
      "-"[r]     //       using hyphens if r = 0, or spaces otherwise
    )            //     end of padEnd()
  ).join`|`      //   end of inner map(); join with pipes
)                // end of outer map()
```
[Answer]
# [PHP](https://php.net/), ~~429~~ 420 bytes
```
$a=preg_split("/
(\W*
)?/",$argv[1]);foreach($a as&$v)$v=array_values(array_filter(explode('|',$v)));for($i=-1;++$i<max(count($a),count($a[0]));)for($j=-1;++$j<=$i;){$t=trim($a[$i][$j]);$u=$a[$i][$j]=trim($a[$j][$i]);$a[$j][$i]=$t;$m[$i]=max(strlen($t),$m[$i]);$m[$j]=max(strlen($u),$m[$j]);}for($k=-1;$b=$a[++$k];print$k?"
":"
$s
")for($l=-1;$b[++$l]!=null;){printf("|%-$m[$l]s",$b[$l]);$s.='|'.str_repeat('-',$m[$l]);}
```
[Try it online!](https://tio.run/##dVLLTsMwELznK0y0EBtSHldSq@LCiRsHDiWqTOsSp85D9qaACN9e1gm0IMEerPHs7M7ESlu0u@mspROUbJ1@XvjWGuTxRcQfH04jMbuIU1DueTu/ykW2bpxWy4KDYsqfwFbAVirn1Ntiq2ynPR8va2NRO65fW9usNE/6JCWtGOY5GDm5ys7OwEwr9cqXTVcjLRTpN5pf5iQVg7b80pZTCSYT74ASnamCCkw@h5JCQScP10O7zANH7T2WgBlUAwrOHp3VNQcU6ciKoVv@7nZjNxh9DJE2IRI8BU8Ktsmz1pkaYTOLo/g6jsBH8ZjdjsKgsvmRrDtr6QsG9ZrH/fEk7LW5pwd@CoDs/bmkxzon74XTrVbIk0mSjjry3@12PbthhVYr7RjBusGC0J64Ux7ZsrFdVRPpNGN91LPJV7ED/IcYOJq4NY4WUfXMNS/sR/Wson@APGrUNY4mYeJeE7X6ewILhYlnBo/23Cc "PHP – Try It Online")
I'm pretty sure it could be golfed a bit more, when I have time I'll try to max it
EDIT: saved 9 bytes by using an alias for `$a[$k]` and using double quotes for the `printf`. Still work to do but 420 is a good number ;)
ungolfed explanation (the outputted newlines also replaced by `\n` for readability):
```
$a=preg_split("/\n(\W*\n)?/",$argv[1]); //split input by line removing the dashes under the headers
foreach($a as&$v)$v=array_values(array_filter(explode('|',$v))); //split each line at the pipes, remove empty cells and rearrange indexes if needed
for($i=-1;++$i<max(count($a),count($a[0]));) //looping on largest array dimension
  for($j=-1;++$j<=$i;){ //swapping array values, trimming strings and we keep the largest length for each column
    $t=trim($a[$i][$j]);
    $u=$a[$i][$j]=trim($a[$j][$i]);
    $a[$j][$i]=$t;
    $m[$i]=max(strlen($t),$m[$i]);
    $m[$j]=max(strlen($u),$m[$j]);
  }
for($k=-1;$b=$a[++$k];print$k?"\n":"\n$s\n") //output of the result with the line
  for($l=-1;$b[++$l]!=null;){
    printf("|%-$m[$l]s",$b[$l]);
    $s.='|'.str_repeat('-',$m[$l]);
  }
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), ~~79~~ ~~71~~ 61 bytes
```
ＷＳ¿¬⁼ιη«≔⟦⟧υＦΦ⪪ι|κ«≔⁻Ｅκμ⌕Ａκ ζ≔✂κ⌊ζ⊕⌈ζ¹κＰ⁺|κＭ⊕¬υ↓⊞υＬκ»ＭＬυ↑|⌈υ↑
```
[Try it online!](https://tio.run/##bVA9b8IwEJ3Jr7hmqS2FgblThiJRQYWablUHKzH4VMcG2ymImt@eniGhldqbfO/ex/lqJVxthe77g0ItgS3MrgtVcGi2jHPYWAfs2Qb2uO@E9gwLUJzwr2xSeo9bw97eC9jzh2xyoc5RB@lYtdMYEjmPOS9AXxWjZIWm82wldkwXYGg@R9OUWqc2h5wTckqOk3XnFdsXUGmsZZqSEtuuZSeiLEztZCtNkA15HQecKilxA@PKS2m2gWxIMqM9Rs9D4p3Hb5RhYRp5TINZAa/YSs/yaU6Jg3PaloaDmeZD0MWtu17gnK3pbGGkPlk0LI8xH54JJuZaNC@4VYGNkfStD35z/oXOUsb1hCms72MJSopGulgaG5R0Y7sUPkBtddcagpzM4nSo2@PfliqLc3SkBojOHuCnYmudJFO6rwmDayWpb/5SgxLh3gOGu6yffupv "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
ＷＳ¿¬⁼ιη«
```
Loop over the input rows, skipping the separator row.
```
≔⟦⟧υ
```
Start collecting the output column cell widths.
```
ＦΦ⪪ι|κ«
```
Split the row on `|`s and loop over the non-empty cells.
```
≔⁻Ｅκμ⌕Ａκ ζ
```
Remove the positions of the spaces from the list of all character indices.
```
≔✂κ⌊ζ⊕⌈ζ¹κ
```
Get the trimmed cell text.
```
Ｐ⁺|κ
```
Print the vertical line and text without moving the cursor.
```
Ｍ⊕¬υ↓
```
Move down one or two lines depending on whether this is the first cell.
```
⊞υＬκ
```
Push the width of the trimmed text to the list.
```
»ＭＬυ↑
```
Move up to the separator row.
```
|⌈υ
```
Print the separator with its vertical line.
```
↑
```
Move to the first row.
[Answer]
# [Perl 5](https://www.perl.org/), ~~269~~ 228 bytes
```
sub f{@t=map[split/\s*\|\s*/],pop()=~/^.\s?(.*?)\s*$/mg;@T=map{$c=$_-1;[map$$\_[$c],@t]}1..@{splice@t,1,1};@w=map{max map y///c,@$\_}@t;splice@T,1,0,[map'-'x$\_,@w];join'',map{(map{sprintf'|%\*s',-$w[$\_],$$r[$_]}0..$#{$r=$_}),$/}@T}
```
[Try it online!](https://tio.run/##pVVdk5owFH3nV9y66QBOBO1MZzrLssvuQ592n2qf1DoUo9Lha0gYdQz96zZBRQVZS5uHEO5Hzj03Z5KEpMHnXUYJvPqU3d9/Z34AauiuVQvuXPDilEAYz7KAYGBLkpJ5nELipgziuTRA4EaLzF0QJdwAijOWZGz6bD88qKql8GdYEndGUigG/@qnlPFvxIujmcJ7F4OfzT2RGcUS7pDP03gl8osZlHOol@tQRzA4GwdguayCl8DXLdVyylLOdz9ZFP7qCmgvDrIwAtk0Hso@CnRGIra3sKXLVAo@@1DwcRihzNYUmS8Zgf14aidWOJT8xPKyGC68x0rhtDwahLdsBYdK3dJbtuWK9x/qea@aWi01@GbEI2BVGqezrCpKKTVQOS7hOaLWPG3xG@Ev0RsRrwO@3DhyqCoMbskAagK/JQ2oifaWXOAk6hsNbc@vLbu23Noya@bVJNQapXekW7@NmsVcv1ua5V2jwf@fRwsWLUj8DYd97bqlyPdrSOT79Sb3kXcptR@/WMpq6QdEKy5XfVtEhxsN@VGCEVknuk2TwPdI4cd9/Mk6hABaxMyeF5H63uhTrTOOpL2D5UKkd4Qr39HsJ8y3DrNDNxnJ/Zg5pt0xF5M5wUmcaLr92/xhjOmTZnSfdGFHZriwnKHM2CLPRtPewBqJH4SmI@RNsMMm@cAwnO2xPDzAg9xyVkWGeJxBfGFjmqaHHTTNHWYdIociso/lXmpPXaMpdlYT61fsR6qKZa4mJ5qkfsTmKv/YpSruodUITScYoVR@875hoLstSkVZuY6RmTvDfLf7Aw "Perl 5 – Try It Online")
```
sub f{
  @t=map[split/\s*\|\s*/],       #split at |, trim away spaces before and after
     pop()=~/^.\s?(.*?)\s*$/mg;  #pick part of each line that matter from input
  @T=map{$c=$_-1;[map$$\_[$c],@t]}#transpose input table @t
 1..@{splice@t,1,1}; #cols
 @w=map{max map y|||c,@$\_}@t; #find max width of cols in transposed table
 splice@T,1,0,[map'-'x$\_,@w]; #insert second line with --- of each width
 join'', #join pieces of output into single string
 map{ #for each line in transposed table @T
 (
 map {
 sprintf '|%\*s', #string right padded...
 -$w[$\_], #...to width of this column
 $$r[$_]                #info in column number $_
      }
      0..$#{$r=$_}               #0..last index of current line in @T
    ),
    $/                           #newline \n (default)
  }
  @T                             #for each line in transposed table @T
}
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 45 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
ā2ÊÏε'|¡õÚðδÚ}©øćU®ε€gà}©'-×šXšεεR®NèjR„| ì]»
```
Input as a list of lines. Outputs with spaces, and without trailing `|`.
[Try it online](https://tio.run/##yy9OTMpM/V/z/0ij0eGuw/3ntqrXHFp4eOvhWYc3nNtyeFbtoZWHdxxpDz207tzWR01r0g8vAIqo6x6efnRhxNGF57ae2xp0aJ3f4RVZQY8a5tUoHF4Te2j3//81Co4KGamJKalFCkBmXn5JBpAFF/BJLC5RSM7PKc3NAwoWpSoo1HDVKOhCgQKCiUMALAbU4ZZZBDQICGoUDBRQQI1Cbj7Q3OT8vJLUvBKIJSAdwalAoRSwgqL8clQdJRmJJerFCpklinAxAA) (the header `|` is to convert the input into a list of lines).
**Explanation:**
```
ā            # Push a list in the range [1, (implicit) input-length]
 2Ê          # Check for each that they're NOT equal to 2
   Ï         # And only leave the lines in the input at truthy indices
             # (so we've removed the second line with the dashes)
ε            # Map each remaining line to:
 '|¡        '#  Split it on "|"
    õÚ       #  Remove leading/trailing empty strings, if the line started and/or ended
             #  with a "|"
       δ     #  Map over each part:
      ð Ú    #   Remove leading/trailing spaces
}©           # After the map: store the result in variable `®` (without popping)
  ø          # Zip/transpose, swapping rows/columns
   ć         # Pop and push remainder-list and first item separated to the stack
    U        # Pop this first item, and store it in variable `X`
 ®           # Push the list of variable `®` again
  ε          # Map over each list:
   €         #  Map over each part:
    g        #   Pop and get the length of the part
   à         #  Pop and only leave the maximum length
  }©         # After the map: store this as new value `®` (without popping)
    '-×     '# Transform each integer in the list into that many "-" as string
       š     # Prepend this list to the remainder-list
        Xš   # And then prepend the extracted head `X` back as well
ε            # Map over each list:
 ε           #  Map over each part inside the list:
  R          #   Reverse the current part
   ®         #   Push the list of integers `®`
    Nè       #   Pop and index the map-index into it
      j      #   Pad leading spaces up to that many characters to the reversed part
       R     #   Then reverse it back so the spaces are trailing
        „| ì #   And prepend "| " to the part
]            # Close the nested maps
 »           # Join each inner list by spaces, and then each string by newlines
             # (after which the result is output implicitly)
```
[Answer]
# [Julia 1.0](http://julialang.org/), ~~146~~ 144 bytes
```
x->["|"*join(rpad.(i,l),"|") for i=zip(insert!.((n=[strip.(split(i,"|";keepempty=0>1)) for i=x[[1;3:end]]];),2,"-".^(l=maximum.(length,n)))...)]
```
input and output are arrays of strings
[Try it online!](https://tio.run/##bY8xT8MwEIX3/IprFmyUWi1sVKnEwsTGGAXJatzmimNbzkWkyP89uKUGgrjp@d3z6XvHQaNcj9O@nMbltspDfnu0aJh3shEMC82L6HHYWw9YfqBjaHrlaSEYM2XVk0cnWO80UkzH6OZNKac6R6dytV3z9HOsqvXm/kGZpq7rDS/uinyZi1emy06O2A2dYFqZA7WF4ZwLIXg9oXEDQQlVlgd4hFbJRnmI0lhqo0pGXpwDy@vAj0zGV@AJfU8QJ4C37/BrroEXtbOm@T@Q1VnWYOwpT@zCxTPn0ZA2jH8v9tcVn0LCDXPY8Cwjw87qoTPR8gpCFhJomHP/eZ6dLKQSYQUzwM7GWxGflKHL4ZhNfcK8TaBW0k0PSIvkfAI "Julia 1.0 – Try It Online")  
[All tests!](https://tio.run/##pVQ7T8MwEN7zKw4v2Ci1eGxUqcTCxMYYghRRlxoSJ3JcUZD/e7kAbmKnLaR4iXPnu@@@e72sCplfrDeLZLOezFJiydlLJRXVdT7nVMYFi1HGYFFpkMmHrKlUjdDmhFOqkrQxWtacNnUhDb7Gp9NXIWpR1uY9WeRFI5izXafpxfTqWqh5lmVTFl/GZEL4Iy2SMl/LclVyWgj1bJaxYoxxzlm2kapemQYSSCNCSGThBpYinwsNeFWVWeLNCVA7@TnQXZ0AtbdSNwbwWNDVG/ROq70XT5Wa79QidBzib5Wd255s6wy8uPbGF8q@rAKCrd9zCI8XbWt1l2M0T1WxKhVaaoEvygo/GJARyjiZWebmtAFpTnbzC@EPZfdQbg9mtgN2uNZHRUIOxPqYqHGY1veKGocYan7HC7O3H39QwF5AfpnsIP/7I@zK8p@mO6bljmm4Y9ptWIOt5wEp21HqdcL@ElivP0I6dkCml318H1IZ1q1XHnskj5E0RrIYSaINP4uir/0MUsH3uo1aT7WWyhSKSub9EkhmQDwZp4tu/z8ogsvbN2llEa79zZ@nDuyIubMjBs/@ZfKc5BM "Julia 1.0 – Try It Online")
Edit: -2 bytes by replacing `false` by `0>1`
[Answer]
# [APL (Dyalog Extended)](https://github.com/abrudz/dyalog-apl-extended), 40 bytes
```
⊃1(,/↑,2↓⊢){'|','-'⍪⍢(1∘⊖)↑⌂deb⍵⊆⍨⍵≠⊃⍵}¨
```
[Try it online!](https://tio.run/##nZDBSsNAEIbvfYrxtC0kaPUJRBAFT8YXiM02KaSJpCsqHS8qQaMpiigepacighd9gT7KvEicbEwlBMF0DruTn/kn37/2kW86Z7YfuqY8VTJwpJNllFx228YqxQ/GOsWPlEw7Y4HCEKag9I3SabtL1y@UPHd4hO4uHHlI6RclMaWzvLl55Q3cnM9nWZ/ie0onWnin9HP@sZGbJk/W/hafBzu7VubyzJg/@BKCbq/6kJtbLgiETfCk7cgIuA1C5XG3EPbskYJe6B8PAxYjCYAi95g/Bb/tH4LWtGd7EPEyLoQ1qBTCMOTdvTDg91HFjwqPJVl09EgUnlQ9yrOVECMYqJWFKJaI1DxQ8zhLhCmilEmwmgNrKfR7lYBY5cVaAj1dJsAqP9bo9XRJj1V2rJNjM/RG4I24/4ktWt8 "APL (Dyalog Extended) – Try It Online")
Adám's method.
**64 bytes(old)**
```
{↑,/⍉↑{'|',¨¯1⌽(m∘↑¨1⌽⍵),⍨⊂'-'/⍨m←⌈/≢¨⍵}¨¯1⌽1↓1⌽⌂deb¨'|'(≠⊆⊢)¨⍵}
```
[Try it online!](https://tio.run/##nVBNS8NAEL33V4ynbaGhFn@BCKLgyfoHYrP9gCaRdEWl46VKaGNTFBE8Sk85CL3o0Ut@yvyRONmYSgiC6Rx2Z9@@N/vemhcjw7oxR27fkNdKOpa0kmRC/lOzReGc94lA0YyjeN2mxVfdptkrg3GUnij8bDQpjCiYCkMwP7LJf6TFrEXzVRzx9W0ubJP/rCWLqSXP44iH1mn@RoFPwaqRcZNeqg6XFNxR@E7hR7ze47do@dI5PeD17Oi4k/SZM@EDb0LQw30PUmmtDwJhHwbStKQH3DquGnC3AU7MsYKuO7q0HQY9CYAi1Rg/Bb/tH4DGtOZw6PEwLoRdKBSC7fLsruvwV6rsoUzTkQxamuK5V0WNGphKiDEM1c4GFFtEqh6oepwtwmRR8iRYzIGlFPq/coNY9IulBJqdJ8Cifyy51@zcPRa9Y9k5VrNeyXgl3/@0LWrf "APL (Dyalog Extended) – Try It Online")
Takes the input as a list of lines, outputs a character matrix.
-9 bytes using `dfns.deb`.
## Explanation
`'|'(≠⊆⊢)¨⍵` split each line on pipes(`|`)
`⌂deb¨` trim whitespace from both sides of each cell
`¯1⌽1↓1⌽` drop the row with hyphens
`{'|',¨¯1⌽(m∘↑¨1⌽⍵),⍨⊂'-'/⍨m←⌈/≢¨⍵}¨` do the following for each row:
`m←⌈/≢¨⍵` set m to the maximum cell length
`⊂'-'/⍨` create a cell of hyphens that long
`,⍨` join with
`m∘↑¨1⌽⍵` input shifted by 1, with each cell padded to length m.
`¯1⌽` shift back to original position
`'|',¨` prepend a pipe to each cell
Finally,
`⍉↑` convert to matrix, and transpose
`↑,/` join each row's cells, and convert to matrix again
]