Skip to content

Commit b4dc23e

Browse files
authored
Merge pull request #571 from tomtomjhj/table-format
Fix TableFormat for indented tables, version 2
2 parents d7038a6 + a046794 commit b4dc23e

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

ftplugin/markdown.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ function! s:TableFormat()
550550
" Move colons for alignment to left or right side of the cell.
551551
execute 's/:\( \+\)|/\1:|/e' . l:flags
552552
execute 's/|\( \+\):/|:\1/e' . l:flags
553-
execute 's/ /-/' . l:flags
553+
execute 's/|:\?\zs[ -]\+\ze:\?|/\=repeat("-", len(submatch(0)))/' . l:flags
554554
call setpos('.', l:pos)
555555
endfunction
556556

test/table-format.vader

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ Expect (table is not modified):
3030
|---|---|
3131
| c | d |
3232

33+
Given markdown (indented table);
34+
| a | b |
35+
|---|---|
36+
| c | d |
37+
38+
Execute (format well formatted, indented table):
39+
TableFormat
40+
41+
Expect (table is not modified):
42+
| a | b |
43+
|---|---|
44+
| c | d |
45+
3346
Given markdown;
3447
| left |right| center ||
3548
| :- | --: |:---:|:|
@@ -42,3 +55,16 @@ Expect (preserve colons to align text):
4255
| left | right | center | |
4356
|:-----|------:|:------:|:--|
4457
| left | right | center | |
58+
59+
Given markdown (indented table with colons);
60+
| left |right| center ||
61+
| :- | --: |:---:|:|
62+
| left |right| center ||
63+
64+
Execute (format indented table with colons):
65+
TableFormat
66+
67+
Expect (preserve colons to align text):
68+
| left | right | center | |
69+
|:-----|------:|:------:|:--|
70+
| left | right | center | |

0 commit comments

Comments
 (0)