Skip to content

Commit

Permalink
TableFormat does not remove colons for alignment
Browse files Browse the repository at this point in the history
Fix #265, #220
  • Loading branch information
shirosaki committed Feb 25, 2016
1 parent 680f0dc commit e07c336
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ftplugin/markdown.vim
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,11 @@ function! s:TableFormat()
" Remove everything that is not a pipe othewise well formated tables would grow
" because of addition of 2 spaces on the separator line by Tabularize /|.
let l:flags = (&gdefault ? '' : 'g')
execute 's/[^|]//' . l:flags
execute 's/\(:\@<!-:\@!\|[^|:-]\)//e' . l:flags
execute 's/--/-/e' . l:flags
Tabularize /|
execute 's/:\( \+\)|/\1:|/e' . l:flags
execute 's/|\( \+\):/|:\1/e' . l:flags
execute 's/ /-/' . l:flags
call setpos('.', l:pos)
endfunction
Expand Down
13 changes: 13 additions & 0 deletions test/table-format.vader
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,16 @@ Expect (table is not modified):
| a | b |
|---|---|
| c | d |

Given markdown;
| left |right| center ||
| :- | --: |:---:|:|
| left |right| center ||

Execute (format table with colons):
TableFormat

Expect (preserve colons to align text):
| left | right | center | |
|:-----|------:|:------:|:--|
| left | right | center | |

0 comments on commit e07c336

Please sign in to comment.