Skip to content

Commit

Permalink
No autoindent in code block
Browse files Browse the repository at this point in the history
Fix #78
  • Loading branch information
shirosaki committed Dec 22, 2015
1 parent deafb57 commit 2918519
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
12 changes: 10 additions & 2 deletions indent/markdown.vim
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ setlocal comments+=b:>
" Only define the function once
if exists("*GetMarkdownIndent") | finish | endif

function! s:is_mkdCode(lnum)
return synIDattr(synID(a:lnum, 1, 0), 'name') == 'mkdCode'
endfunction

function! s:is_li_start(line)
return a:line !~ '^ *\([*-]\)\%( *\1\)\{2}\%( \|\1\)*$' &&
\ a:line =~ '^\s*[*+-] \+'
Expand Down Expand Up @@ -48,8 +52,12 @@ function GetMarkdownIndent()
" Current line is the first line of a list item, do not change indent
return indent(v:lnum)
elseif s:is_li_start(line)
" Last line is the first line of a list item, increase indent
return ind + list_ind
if s:is_mkdCode(lnum)
return ind
else
" Last line is the first line of a list item, increase indent
return ind + list_ind
end
else
return ind
endif
Expand Down
16 changes: 14 additions & 2 deletions test/indent.vader
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Given markdown;
* item1

Do (Insert enter at list end):
Do (insert enter at list end):
A\<Enter>item2

Expect (auto insert * and indent level is same):
Expand All @@ -13,7 +13,7 @@ Given markdown;
Execute:
syntax off

Do (Insert enter at list end with syntax off):
Do (insert enter at list end with syntax off):
i* item1\<Enter>item2

Expect (auto insert * and indent level is same):
Expand All @@ -22,3 +22,15 @@ Expect (auto insert * and indent level is same):

Execute:
syntax on

Given markdown;
```
* item1

Do (insert after list items in code block):
jotext

Expect (no autoindent in code block):
```
* item1
text

0 comments on commit 2918519

Please sign in to comment.