From f384aa6d1e6a23c9ee5ef6168a3376a7833081b0 Mon Sep 17 00:00:00 2001 From: Steven Schmeiser Date: Thu, 17 Aug 2017 09:59:04 -0400 Subject: [PATCH 1/6] add horizontal alignment to tables --- autoload/vimwiki/tbl.vim | 69 ++++++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 14 deletions(-) diff --git a/autoload/vimwiki/tbl.vim b/autoload/vimwiki/tbl.vim index b05d67c..d720c9c 100644 --- a/autoload/vimwiki/tbl.vim +++ b/autoload/vimwiki/tbl.vim @@ -57,7 +57,7 @@ function! s:is_table(line) "{{{ endfunction "}}} function! s:is_separator(line) "{{{ - return a:line =~# '^\s*'.s:rxSep().'\(--\+'.s:rxSep().'\)\+\s*$' + return a:line =~# '^\s*'.s:rxSep().'\(:\=--\+:\='.s:rxSep().'\)\+\s*$' endfunction "}}} function! s:is_separator_tail(line) "{{{ @@ -234,6 +234,33 @@ function! s:get_rows(lnum) "{{{ return upper_rows + lower_rows endfunction "}}} +function! s:get_cell_aligns(lnum) "{{{ + let aligns = {} + for [lnum, row] in s:get_rows(a:lnum) + if s:is_separator(row) + let cells = vimwiki#tbl#get_cells(row) + for idx in range(len(cells)) + let cell = cells[idx] + if cell =~# '^--\+:' + let aligns[idx] = 'right' + elseif cell =~# '^:--\+:' + let aligns[idx] = 'center' + else + let aligns[idx] = 'left' + endif + endfor + else + let cells = vimwiki#tbl#get_cells(row) + for idx in range(len(cells)) + if !has_key(aligns, idx) + let aligns[idx] = 'left' + endif + endfor + endif + endfor + return aligns +endfunction "}}} + function! s:get_cell_max_lens(lnum, ...) "{{{ let max_lens = {} for [lnum, row] in s:get_rows(a:lnum) @@ -261,12 +288,13 @@ function! s:get_aligned_rows(lnum, col1, col2) "{{{ call add(cells, vimwiki#tbl#get_cells(row)) endfor let max_lens = s:get_cell_max_lens(a:lnum, cells, startlnum) + let aligns = s:get_cell_aligns(a:lnum) let result = [] for [lnum, row] in rows if s:is_separator(row) - let new_row = s:fmt_sep(max_lens, a:col1, a:col2) + let new_row = s:fmt_sep(max_lens, aligns, a:col1, a:col2) else - let new_row = s:fmt_row(cells[lnum - startlnum], max_lens, a:col1, a:col2) + let new_row = s:fmt_row(cells[lnum - startlnum], max_lens, aligns, a:col1, a:col2) endif call add(result, [lnum, new_row]) endfor @@ -296,19 +324,24 @@ endfunction "}}} " }}} " Format functions {{{ -function! s:fmt_cell(cell, max_len) "{{{ +function! s:fmt_cell(cell, max_len, align) "{{{ let cell = ' '.a:cell.' ' let diff = a:max_len - s:wide_len(a:cell) if diff == 0 && empty(a:cell) let diff = 1 endif - - let cell .= repeat(' ', diff) + if a:align == 'left' + let cell .= repeat(' ', diff) + elseif a:align == 'right' + let cell = repeat(' ',diff).cell + else + let cell = repeat(' ',diff/2).cell.repeat(' ',diff-diff/2) + endif return cell endfunction "}}} -function! s:fmt_row(cells, max_lens, col1, col2) "{{{ +function! s:fmt_row(cells, max_lens, aligns, col1, col2) "{{{ let new_line = s:rxSep() for idx in range(len(a:cells)) if idx == a:col1 @@ -317,26 +350,34 @@ function! s:fmt_row(cells, max_lens, col1, col2) "{{{ let idx = a:col1 endif let value = a:cells[idx] - let new_line .= s:fmt_cell(value, a:max_lens[idx]).s:rxSep() + let new_line .= s:fmt_cell(value, a:max_lens[idx], a:aligns[idx]).s:rxSep() endfor let idx = len(a:cells) while idx < len(a:max_lens) - let new_line .= s:fmt_cell('', a:max_lens[idx]).s:rxSep() + let new_line .= s:fmt_cell('', a:max_lens[idx], a:aligns[idx]).s:rxSep() let idx += 1 endwhile return new_line endfunction "}}} -function! s:fmt_cell_sep(max_len) "{{{ +function! s:fmt_cell_sep(max_len, align) "{{{ + let cell = '' if a:max_len == 0 - return repeat('-', 3) + let cell .= '-' else - return repeat('-', a:max_len+2) + let cell .= repeat('-', a:max_len) + endif + if a:align == 'right' + return cell.'-:' + elseif a:align == 'left' + return cell.'--' + else + return ':'.cell.':' endif endfunction "}}} -function! s:fmt_sep(max_lens, col1, col2) "{{{ +function! s:fmt_sep(max_lens, aligns, col1, col2) "{{{ let new_line = s:rxSep() for idx in range(len(a:max_lens)) if idx == a:col1 @@ -344,7 +385,7 @@ function! s:fmt_sep(max_lens, col1, col2) "{{{ elseif idx == a:col2 let idx = a:col1 endif - let new_line .= s:fmt_cell_sep(a:max_lens[idx]).s:rxSep() + let new_line .= s:fmt_cell_sep(a:max_lens[idx], a:aligns[idx]).s:rxSep() endfor return new_line endfunction "}}} From 7730fa28b536f06b7701166e3fc54c23e1338682 Mon Sep 17 00:00:00 2001 From: Steven Schmeiser Date: Thu, 17 Aug 2017 10:08:32 -0400 Subject: [PATCH 2/6] add horizontal alignment to table documentation --- doc/vimwiki.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt index bc8db38..247a0d1 100644 --- a/doc/vimwiki.txt +++ b/doc/vimwiki.txt @@ -1658,6 +1658,15 @@ values: > To indent table indent the first row. Then format it with 'gqq'. +You can specify horizontal alignment for columns in the separator. The +default is left-align. > + + | Date | Item | Price | + |------------|:------:|--------:| + | yest | Coffee | $15.00 | + | 2017-02-13 | Tea | $2.10 | + | 2017-03-14 | Cake | $143.12 | +< ============================================================================== 10. Diary *vimwiki-diary* From 23d273d54711035ac2b1c19838438521f0982595 Mon Sep 17 00:00:00 2001 From: Steven Schmeiser Date: Mon, 9 Jul 2018 10:05:30 -0400 Subject: [PATCH 3/6] table alignment: break out of loop when separator found --- autoload/vimwiki/tbl.vim | 16 +++++++++------- doc/vimwiki.txt | 4 ++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/autoload/vimwiki/tbl.vim b/autoload/vimwiki/tbl.vim index d720c9c..f395a11 100644 --- a/autoload/vimwiki/tbl.vim +++ b/autoload/vimwiki/tbl.vim @@ -237,7 +237,9 @@ endfunction "}}} function! s:get_cell_aligns(lnum) "{{{ let aligns = {} for [lnum, row] in s:get_rows(a:lnum) + let found_separator = 0 if s:is_separator(row) + let found_separator = 1 let cells = vimwiki#tbl#get_cells(row) for idx in range(len(cells)) let cell = cells[idx] @@ -249,15 +251,15 @@ function! s:get_cell_aligns(lnum) "{{{ let aligns[idx] = 'left' endif endfor - else - let cells = vimwiki#tbl#get_cells(row) - for idx in range(len(cells)) - if !has_key(aligns, idx) - let aligns[idx] = 'left' - endif - endfor + return aligns endif endfor + if !found_separator + let cells = vimwiki#tbl#get_cells(row) + for idx in range(len(cells)) + let aligns[idx] = 'left' + endfor + endif return aligns endfunction "}}} diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt index 247a0d1..d2ec6f2 100644 --- a/doc/vimwiki.txt +++ b/doc/vimwiki.txt @@ -1658,8 +1658,8 @@ values: > To indent table indent the first row. Then format it with 'gqq'. -You can specify horizontal alignment for columns in the separator. The -default is left-align. > +You can specify the type of horizontal alignment for columns in the separator +using the ':' character. The default is left-align. > | Date | Item | Price | |------------|:------:|--------:| From e26d9fdb8efb2b6d345595981972809ffd1f3b3c Mon Sep 17 00:00:00 2001 From: Rane Date: Thu, 14 Mar 2019 14:03:42 -0600 Subject: [PATCH 4/6] Fix bold and italic markdown syntax --- syntax/vimwiki_markdown.vim | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/syntax/vimwiki_markdown.vim b/syntax/vimwiki_markdown.vim index 5962699..0740712 100644 --- a/syntax/vimwiki_markdown.vim +++ b/syntax/vimwiki_markdown.vim @@ -13,23 +13,21 @@ let s:markdown_syntax = g:vimwiki_syntax_variables['markdown'] let s:markdown_syntax.rxEqIn = '\$[^$`]\+\$' let s:markdown_syntax.char_eqin = '\$' -" text: *strong* -" let s:markdown_syntax.rxBold = '\*[^*]\+\*' +" text: **strong** or __strong__ let s:markdown_syntax.rxBold = '\%(^\|\s\|[[:punct:]]\)\@<='. - \'\*'. - \'\%([^*`[:space:]][^*`]*[^*`[:space:]]\|[^*`[:space:]]\)'. - \'\*'. + \'\(\*\|_\)\{2\}'. + \'\%([^*_`[:space:]][^*_`]*[^*_`[:space:]]\|[^*_`[:space:]]\)'. + \'\1\{2\}'. \'\%([[:punct:]]\|\s\|$\)\@=' -let s:markdown_syntax.char_bold = '*' +let s:markdown_syntax.char_bold = '\*\*\|__' -" text: _emphasis_ -" let s:markdown_syntax.rxItalic = '_[^_]\+_' +" text: _emphasis_ or *emphasis* let s:markdown_syntax.rxItalic = '\%(^\|\s\|[[:punct:]]\)\@<='. - \'_'. - \'\%([^_`[:space:]][^_`]*[^_`[:space:]]\|[^_`[:space:]]\)'. - \'_'. + \'\(\*\|_\)'. + \'\%([^*_`[:space:]][^*_`]*[^*_`[:space:]]\|[^*_`[:space:]]\)'. + \'\1'. \'\%([[:punct:]]\|\s\|$\)\@=' -let s:markdown_syntax.char_italic = '_' +let s:markdown_syntax.char_italic = '\*\|_' " text: *_bold italic_* or _*italic bold*_ let s:markdown_syntax.rxBoldItalic = '\%(^\|\s\|[[:punct:]]\)\@<='. From 6b29b6604c0a82e3078e17ac08a669c957a0126d Mon Sep 17 00:00:00 2001 From: Rane Date: Thu, 14 Mar 2019 15:21:04 -0600 Subject: [PATCH 5/6] Fix bold_italic and italic_bold markdown syntax. --- syntax/vimwiki.vim | 2 +- syntax/vimwiki_markdown.vim | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/syntax/vimwiki.vim b/syntax/vimwiki.vim index 512aad9..6a2f9cf 100644 --- a/syntax/vimwiki.vim +++ b/syntax/vimwiki.vim @@ -383,7 +383,7 @@ hi def link VimwikiBoldT VimwikiBold hi def VimwikiItalic term=italic cterm=italic gui=italic hi def link VimwikiItalicT VimwikiItalic -hi def VimwikiBoldItalic term=bold cterm=bold gui=bold,italic +hi def VimwikiBoldItalic term=bold,italic cterm=bold,italic gui=bold,italic hi def link VimwikiItalicBold VimwikiBoldItalic hi def link VimwikiBoldItalicT VimwikiBoldItalic hi def link VimwikiItalicBoldT VimwikiBoldItalic diff --git a/syntax/vimwiki_markdown.vim b/syntax/vimwiki_markdown.vim index 0740712..05e1f34 100644 --- a/syntax/vimwiki_markdown.vim +++ b/syntax/vimwiki_markdown.vim @@ -31,18 +31,18 @@ let s:markdown_syntax.char_italic = '\*\|_' " text: *_bold italic_* or _*italic bold*_ let s:markdown_syntax.rxBoldItalic = '\%(^\|\s\|[[:punct:]]\)\@<='. - \'\*_'. - \'\%([^*_`[:space:]][^*_`]*[^*_`[:space:]]\|[^*_`[:space:]]\)'. - \'_\*'. + \'\(\*\)\{3\}'. + \'\%([^*`[:space:]][^*`]*[^*`[:space:]]\|[^*`[:space:]]\)'. + \'\1\{3\}'. \'\%([[:punct:]]\|\s\|$\)\@=' -let s:markdown_syntax.char_bolditalic = '\*_' +let s:markdown_syntax.char_bolditalic = '\*\*\*' let s:markdown_syntax.rxItalicBold = '\%(^\|\s\|[[:punct:]]\)\@<='. - \'_\*'. - \'\%([^*_`[:space:]][^*_`]*[^*_`[:space:]]\|[^*_`[:space:]]\)'. - \'\*_'. + \'\(_\)\{3\}'. + \'\%([^_`[:space:]][^_`]*[^_`[:space:]]\|[^_`[:space:]]\)'. + \'\1\{3\}'. \'\%([[:punct:]]\|\s\|$\)\@=' -let s:markdown_syntax.char_italicbold = '_\*' +let s:markdown_syntax.char_italicbold = '___' " text: `code` let s:markdown_syntax.rxCode = '`[^`]\+`' From 1f1966a4f643897668c4b797a8f2af6811db25eb Mon Sep 17 00:00:00 2001 From: Rane Date: Fri, 15 Mar 2019 06:12:35 -0600 Subject: [PATCH 6/6] Add description of markdown specific text decorators --- doc/vimwiki.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt index 4f935e5..908c9b3 100644 --- a/doc/vimwiki.txt +++ b/doc/vimwiki.txt @@ -877,6 +877,12 @@ is decorated: > super^script^ sub,,script,, +For Markdown syntax these variations are used: > + + **bold text** or __bold text__ + *italic text* or _italic text_ + ***bold_italic text*** or ___italic_bold text___ + Furthermore, there are a number of words which are highlighted extra flashy: TODO, DONE, STARTED, FIXME, FIXED, XXX.