Skip to content

Commit

Permalink
LSP.MarkupContent: Partial compact
Browse files Browse the repository at this point in the history
  • Loading branch information
hrsh7th committed Oct 6, 2022
1 parent 5b35da1 commit b5f801d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
16 changes: 9 additions & 7 deletions autoload/vital/__vital__/VS/LSP/MarkupContent.vim
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,21 @@ function! s:normalize(markup_content, ...) abort
endif
endif
let l:normalized = s:Text.normalize_eol(l:normalized)
if l:option.compact
let l:normalized = s:_compact(l:normalized)
endif
let l:normalized = s:_format(l:normalized, l:option.compact)
return l:normalized
endfunction

"
" _compact
" _format
"
function! s:_compact(string) abort
function! s:_format(string, compact) abort
let l:string = a:string
let l:string = substitute(l:string, "\\%(\\s\\|\n\\)*```\\s*\\(\\w\\+\\)\\%(\\s\\|\n\\)\\+", "\n\n```\\1 ", 'g')
let l:string = substitute(l:string, "\\%(\\s\\|\n\\)\\+```\\%(\\s*\\%(\\%$\\|\n\\)\\)\\+", " ```\n\n", 'g')
if a:compact
let l:string = substitute(l:string, "\\%(\\s\\|\n\\)*```\\s*\\(\\w\\+\\)\\%(\\s\\|\n\\)\\+", "\n\n```\\1 ", 'g')
let l:string = substitute(l:string, "\\%(\\s\\|\n\\)\\+```\\%(\\s*\\%(\\%$\\|\n\\)\\)\\+", " ```\n\n", 'g')
else
let l:string = substitute(l:string, "```\n\\zs\\%(\\s\\|\n\\)\\+", "", 'g')
endif
let l:string = substitute(l:string, "\\%^\\%(\\s\\|\n\\)*", '', 'g')
let l:string = substitute(l:string, "\\%(\\s\\|\n\\)*\\%$", '', 'g')
return l:string
Expand Down
1 change: 0 additions & 1 deletion autoload/vital/__vital__/VS/LSP/MarkupContent.vimspec
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ Describe vital#__vital__#VS#LSP#MarkupContent
\ '```typescript',
\ 'console.log(variable)',
\ '```',
\ '',
\ '```typescript',
\ 'console.log(variable)',
\ '```',
Expand Down

0 comments on commit b5f801d

Please sign in to comment.