Mercurial > vim
annotate runtime/ftplugin/markdown.vim @ 19464:f26f4ce18b1a
Added tag v8.2.0289 for changeset 798fce18d0491b5bf82097cbbe4ad35974e714bc
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 20 Feb 2020 22:30:05 +0100 |
parents | 5c40013d45ee |
children | 3295247d97a5 |
rev | line source |
---|---|
2202 | 1 " Vim filetype plugin |
2 " Language: Markdown | |
3 " Maintainer: Tim Pope <vimNOSPAM@tpope.org> | |
18818 | 4 " Last Change: 2019 Dec 05 |
2202 | 5 |
6 if exists("b:did_ftplugin") | |
7 finish | |
8 endif | |
9 | |
10 runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim | |
11 | |
18818 | 12 setlocal comments=fb:*,fb:-,fb:+,n:> commentstring=<!--%s--> |
4681
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
3224
diff
changeset
|
13 setlocal formatoptions+=tcqln formatoptions-=r formatoptions-=o |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
14 setlocal formatlistpat=^\\s*\\d\\+\\.\\s\\+\\\|^[-*+]\\s\\+\\\|^\\[^\\ze[^\\]]\\+\\]: |
2202 | 15 |
3224 | 16 if exists('b:undo_ftplugin') |
17 let b:undo_ftplugin .= "|setl cms< com< fo< flp<" | |
18 else | |
19 let b:undo_ftplugin = "setl cms< com< fo< flp<" | |
20 endif | |
2202 | 21 |
18818 | 22 function! s:NotCodeBlock(lnum) abort |
23 return synIDattr(synID(v:lnum, 1, 1), 'name') !=# 'markdownCode' | |
24 endfunction | |
25 | |
26 function! MarkdownFold() abort | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
27 let line = getline(v:lnum) |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
28 |
18818 | 29 if line =~# '^#\+ ' && s:NotCodeBlock(v:lnum) |
30 return ">" . match(line, ' ') | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
31 endif |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
32 |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
33 let nextline = getline(v:lnum + 1) |
18818 | 34 if (line =~ '^.\+$') && (nextline =~ '^=\+$') && s:NotCodeBlock(v:lnum + 1) |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
35 return ">1" |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
36 endif |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
37 |
18818 | 38 if (line =~ '^.\+$') && (nextline =~ '^-\+$') && s:NotCodeBlock(v:lnum + 1) |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
39 return ">2" |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
40 endif |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
41 |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
42 return "=" |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
43 endfunction |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
44 |
18818 | 45 function! s:HashIndent(lnum) abort |
46 let hash_header = matchstr(getline(a:lnum), '^#\{1,6}') | |
47 if len(hash_header) | |
48 return hash_header | |
49 else | |
50 let nextline = getline(a:lnum + 1) | |
51 if nextline =~# '^=\+\s*$' | |
52 return '#' | |
53 elseif nextline =~# '^-\+\s*$' | |
54 return '##' | |
55 endif | |
56 endif | |
57 endfunction | |
58 | |
59 function! MarkdownFoldText() abort | |
60 let hash_indent = s:HashIndent(v:foldstart) | |
61 let title = substitute(getline(v:foldstart), '^#\+\s*', '', '') | |
62 let foldsize = (v:foldend - v:foldstart + 1) | |
63 let linecount = '['.foldsize.' lines]' | |
64 return hash_indent.' '.title.' '.linecount | |
65 endfunction | |
66 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
67 if has("folding") && exists("g:markdown_folding") |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
68 setlocal foldexpr=MarkdownFold() |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
69 setlocal foldmethod=expr |
18818 | 70 setlocal foldtext=MarkdownFoldText() |
71 let b:undo_ftplugin .= " foldexpr< foldmethod< foldtext<" | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
72 endif |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
73 |
2202 | 74 " vim:set sw=2: |