Skip to content

Commit

Permalink
Merge pull request #571 from tomtomjhj/table-format
Browse files Browse the repository at this point in the history
Fix TableFormat for indented tables, version 2
  • Loading branch information
tomtomjhj authored Feb 9, 2022
2 parents d7038a6 + a046794 commit b4dc23e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ftplugin/markdown.vim
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ function! s:TableFormat()
" Move colons for alignment to left or right side of the cell.
execute 's/:\( \+\)|/\1:|/e' . l:flags
execute 's/|\( \+\):/|:\1/e' . l:flags
execute 's/ /-/' . l:flags
execute 's/|:\?\zs[ -]\+\ze:\?|/\=repeat("-", len(submatch(0)))/' . l:flags
call setpos('.', l:pos)
endfunction

Expand Down
26 changes: 26 additions & 0 deletions test/table-format.vader
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ Expect (table is not modified):
|---|---|
| c | d |

Given markdown (indented table);
| a | b |
|---|---|
| c | d |

Execute (format well formatted, indented table):
TableFormat

Expect (table is not modified):
| a | b |
|---|---|
| c | d |

Given markdown;
| left |right| center ||
| :- | --: |:---:|:|
Expand All @@ -42,3 +55,16 @@ Expect (preserve colons to align text):
| left | right | center | |
|:-----|------:|:------:|:--|
| left | right | center | |

Given markdown (indented table with colons);
| left |right| center ||
| :- | --: |:---:|:|
| left |right| center ||

Execute (format indented table with colons):
TableFormat

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

0 comments on commit b4dc23e

Please sign in to comment.