mirror of
https://github.com/tpope/vim-markdown.git
synced 2025-11-20 07:43:41 -05:00
Merge branch 'master' of https://github.com/tpope/vim-markdown into readme-update
This commit is contained in:
2
.github/FUNDING.yml
vendored
Normal file
2
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
github: tpope
|
||||||
|
custom: ["https://www.paypal.me/vimpope"]
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
" Vim filetype plugin
|
" Vim filetype plugin
|
||||||
" Language: Markdown
|
" Language: Markdown
|
||||||
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
|
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
|
||||||
" Last Change: 2013 May 30
|
" Last Change: 2019 Dec 05
|
||||||
|
|
||||||
if exists("b:did_ftplugin")
|
if exists("b:did_ftplugin")
|
||||||
finish
|
finish
|
||||||
@@ -19,29 +19,52 @@ else
|
|||||||
let b:undo_ftplugin = "setl cms< com< fo< flp<"
|
let b:undo_ftplugin = "setl cms< com< fo< flp<"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
function! MarkdownFold()
|
if !exists("g:no_plugin_maps") && !exists("g:no_markdown_maps")
|
||||||
|
nnoremap <silent><buffer> [[ :<C-U>call search('\%(^#\{1,5\}\s\+\S\\|^\S.*\n^[=-]\+$\)', "bsW")<CR>
|
||||||
|
nnoremap <silent><buffer> ]] :<C-U>call search('\%(^#\{1,5\}\s\+\S\\|^\S.*\n^[=-]\+$\)', "sW")<CR>
|
||||||
|
xnoremap <silent><buffer> [[ :<C-U>exe "normal! gv"<Bar>call search('\%(^#\{1,5\}\s\+\S\\|^\S.*\n^[=-]\+$\)', "bsW")<CR>
|
||||||
|
xnoremap <silent><buffer> ]] :<C-U>exe "normal! gv"<Bar>call search('\%(^#\{1,5\}\s\+\S\\|^\S.*\n^[=-]\+$\)', "sW")<CR>
|
||||||
|
let b:undo_ftplugin .= '|sil! nunmap <buffer> [[|sil! nunmap <buffer> ]]|sil! xunmap <buffer> [[|sil! xunmap <buffer> ]]'
|
||||||
|
endif
|
||||||
|
|
||||||
|
function! s:NotCodeBlock(lnum) abort
|
||||||
|
return synIDattr(synID(v:lnum, 1, 1), 'name') !=# 'markdownCode'
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! MarkdownFold() abort
|
||||||
let line = getline(v:lnum)
|
let line = getline(v:lnum)
|
||||||
|
|
||||||
" Regular headers
|
if line =~# '^#\+ ' && s:NotCodeBlock(v:lnum)
|
||||||
let depth = match(line, '\(^#\+\)\@<=\( .*$\)\@=')
|
return ">" . match(line, ' ')
|
||||||
if depth > 0
|
|
||||||
return ">" . depth
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Setext style headings
|
|
||||||
let nextline = getline(v:lnum + 1)
|
let nextline = getline(v:lnum + 1)
|
||||||
if (line =~ '^.\+$') && (nextline =~ '^=\+$')
|
if (line =~ '^.\+$') && (nextline =~ '^=\+$') && s:NotCodeBlock(v:lnum + 1)
|
||||||
return ">1"
|
return ">1"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if (line =~ '^.\+$') && (nextline =~ '^-\+$')
|
if (line =~ '^.\+$') && (nextline =~ '^-\+$') && s:NotCodeBlock(v:lnum + 1)
|
||||||
return ">2"
|
return ">2"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return "="
|
return "="
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! MarkdownFoldText()
|
function! s:HashIndent(lnum) abort
|
||||||
|
let hash_header = matchstr(getline(a:lnum), '^#\{1,6}')
|
||||||
|
if len(hash_header)
|
||||||
|
return hash_header
|
||||||
|
else
|
||||||
|
let nextline = getline(a:lnum + 1)
|
||||||
|
if nextline =~# '^=\+\s*$'
|
||||||
|
return '#'
|
||||||
|
elseif nextline =~# '^-\+\s*$'
|
||||||
|
return '##'
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! MarkdownFoldText() abort
|
||||||
let hash_indent = s:HashIndent(v:foldstart)
|
let hash_indent = s:HashIndent(v:foldstart)
|
||||||
let title = substitute(getline(v:foldstart), '^#\+\s*', '', '')
|
let title = substitute(getline(v:foldstart), '^#\+\s*', '', '')
|
||||||
let foldsize = (v:foldend - v:foldstart + 1)
|
let foldsize = (v:foldend - v:foldstart + 1)
|
||||||
@@ -49,22 +72,6 @@ function! MarkdownFoldText()
|
|||||||
return hash_indent.' '.title.' '.linecount
|
return hash_indent.' '.title.' '.linecount
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:HashIndent(lnum)
|
|
||||||
let hash_header = matchstr(getline(a:lnum), '^#\{1,6}')
|
|
||||||
if len(hash_header) > 0
|
|
||||||
" hashtag header
|
|
||||||
return hash_header
|
|
||||||
else
|
|
||||||
" == or -- header
|
|
||||||
let nextline = getline(a:lnum + 1)
|
|
||||||
if nextline =~ '^=\+\s*$'
|
|
||||||
return repeat('#', 1)
|
|
||||||
elseif nextline =~ '^-\+\s*$'
|
|
||||||
return repeat('#', 2)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
if has("folding") && exists("g:markdown_folding")
|
if has("folding") && exists("g:markdown_folding")
|
||||||
setlocal foldexpr=MarkdownFold()
|
setlocal foldexpr=MarkdownFold()
|
||||||
setlocal foldmethod=expr
|
setlocal foldmethod=expr
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
" Language: Markdown
|
" Language: Markdown
|
||||||
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
|
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
|
||||||
" Filenames: *.markdown
|
" Filenames: *.markdown
|
||||||
" Last Change: 2013 May 30
|
" Last Change: 2020 Jan 14
|
||||||
|
|
||||||
if exists("b:current_syntax")
|
if exists("b:current_syntax")
|
||||||
finish
|
finish
|
||||||
@@ -12,6 +12,10 @@ if !exists('main_syntax')
|
|||||||
let main_syntax = 'markdown'
|
let main_syntax = 'markdown'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if has('folding')
|
||||||
|
let s:foldmethod = &l:foldmethod
|
||||||
|
endif
|
||||||
|
|
||||||
runtime! syntax/html.vim
|
runtime! syntax/html.vim
|
||||||
unlet! b:current_syntax
|
unlet! b:current_syntax
|
||||||
|
|
||||||
@@ -33,19 +37,24 @@ endfor
|
|||||||
unlet! s:type
|
unlet! s:type
|
||||||
unlet! s:done_include
|
unlet! s:done_include
|
||||||
|
|
||||||
|
if exists('s:foldmethod') && s:foldmethod !=# &l:foldmethod
|
||||||
|
let &l:foldmethod = s:foldmethod
|
||||||
|
unlet s:foldmethod
|
||||||
|
endif
|
||||||
|
|
||||||
if !exists('g:markdown_minlines')
|
if !exists('g:markdown_minlines')
|
||||||
let g:markdown_minlines = 50
|
let g:markdown_minlines = 50
|
||||||
endif
|
endif
|
||||||
execute 'syn sync minlines=' . g:markdown_minlines
|
execute 'syn sync minlines=' . g:markdown_minlines
|
||||||
syn case ignore
|
syn case ignore
|
||||||
|
|
||||||
syn match markdownValid '[<>]\c[a-z/$!]\@!'
|
syn match markdownValid '[<>]\c[a-z/$!]\@!' transparent contains=NONE
|
||||||
syn match markdownValid '&\%(#\=\w*;\)\@!'
|
syn match markdownValid '&\%(#\=\w*;\)\@!' transparent contains=NONE
|
||||||
|
|
||||||
syn match markdownLineStart "^[<@]\@!" nextgroup=@markdownBlock,htmlSpecialChar
|
syn match markdownLineStart "^[<@]\@!" nextgroup=@markdownBlock,htmlSpecialChar
|
||||||
|
|
||||||
syn cluster markdownBlock contains=markdownH1,markdownH2,markdownH3,markdownH4,markdownH5,markdownH6,markdownBlockquote,markdownListMarker,markdownOrderedListMarker,markdownCodeBlock,markdownRule
|
syn cluster markdownBlock contains=markdownH1,markdownH2,markdownH3,markdownH4,markdownH5,markdownH6,markdownBlockquote,markdownListMarker,markdownOrderedListMarker,markdownCodeBlock,markdownRule
|
||||||
syn cluster markdownInline contains=markdownLineBreak,markdownLinkText,markdownItalic,markdownBold,markdownCode,markdownEscape,@htmlTop,markdownError
|
syn cluster markdownInline contains=markdownLineBreak,markdownLinkText,markdownItalic,markdownBold,markdownCode,markdownEscape,@htmlTop,markdownError,markdownValid
|
||||||
|
|
||||||
syn match markdownH1 "^.\+\n=\+$" contained contains=@markdownInline,markdownHeadingRule,markdownAutomaticLink
|
syn match markdownH1 "^.\+\n=\+$" contained contains=@markdownInline,markdownHeadingRule,markdownAutomaticLink
|
||||||
syn match markdownH2 "^.\+\n-\+$" contained contains=@markdownInline,markdownHeadingRule,markdownAutomaticLink
|
syn match markdownH2 "^.\+\n-\+$" contained contains=@markdownInline,markdownHeadingRule,markdownAutomaticLink
|
||||||
@@ -79,7 +88,7 @@ syn region markdownUrlTitle matchgroup=markdownUrlTitleDelimiter start=+"+ end=+
|
|||||||
syn region markdownUrlTitle matchgroup=markdownUrlTitleDelimiter start=+'+ end=+'+ keepend contained
|
syn region markdownUrlTitle matchgroup=markdownUrlTitleDelimiter start=+'+ end=+'+ keepend contained
|
||||||
syn region markdownUrlTitle matchgroup=markdownUrlTitleDelimiter start=+(+ end=+)+ keepend contained
|
syn region markdownUrlTitle matchgroup=markdownUrlTitleDelimiter start=+(+ end=+)+ keepend contained
|
||||||
|
|
||||||
syn region markdownLinkText matchgroup=markdownLinkTextDelimiter start="!\=\[\%(\_[^]]*]\%( \=[[(]\)\)\@=" end="\]\%( \=[[(]\)\@=" nextgroup=markdownLink,markdownId skipwhite contains=@markdownInline,markdownLineStart
|
syn region markdownLinkText matchgroup=markdownLinkTextDelimiter start="!\=\[\%(\%(\_[^][]\|\[\_[^][]*\]\)*]\%( \=[[(]\)\)\@=" end="\]\%( \=[[(]\)\@=" nextgroup=markdownLink,markdownId skipwhite contains=@markdownInline,markdownLineStart
|
||||||
syn region markdownLink matchgroup=markdownLinkDelimiter start="(" end=")" contains=markdownUrl keepend contained
|
syn region markdownLink matchgroup=markdownLinkDelimiter start="(" end=")" contains=markdownUrl keepend contained
|
||||||
syn region markdownId matchgroup=markdownIdDelimiter start="\[" end="\]" keepend contained
|
syn region markdownId matchgroup=markdownIdDelimiter start="\[" end="\]" keepend contained
|
||||||
syn region markdownAutomaticLink matchgroup=markdownUrlDelimiter start="<\%(\w\+:\|[[:alnum:]_+-]\+@\)\@=" end=">" keepend oneline
|
syn region markdownAutomaticLink matchgroup=markdownUrlDelimiter start="<\%(\w\+:\|[[:alnum:]_+-]\+@\)\@=" end=">" keepend oneline
|
||||||
@@ -88,16 +97,17 @@ let s:concealends = ''
|
|||||||
if has('conceal') && get(g:, 'markdown_syntax_conceal', 1) == 1
|
if has('conceal') && get(g:, 'markdown_syntax_conceal', 1) == 1
|
||||||
let s:concealends = ' concealends'
|
let s:concealends = ' concealends'
|
||||||
endif
|
endif
|
||||||
exe 'syn region markdownItalic matchgroup=markdownItalicDelimiter start="\S\@<=\*\|\*\S\@=" end="\S\@<=\*\|\*\S\@=" keepend contains=markdownLineStart,@Spell' . s:concealends
|
exe 'syn region markdownItalic matchgroup=markdownItalicDelimiter start="\S\@<=\*\|\*\S\@=" end="\S\@<=\*\|\*\S\@=" skip="\\\*" contains=markdownLineStart,@Spell' . s:concealends
|
||||||
exe 'syn region markdownItalic matchgroup=markdownItalicDelimiter start="\S\@<=_\|_\S\@=" end="\S\@<=_\|_\S\@=" keepend contains=markdownLineStart,@Spell' . s:concealends
|
exe 'syn region markdownItalic matchgroup=markdownItalicDelimiter start="\w\@<!_\S\@=" end="\S\@<=_\w\@!" skip="\\_" contains=markdownLineStart,@Spell' . s:concealends
|
||||||
exe 'syn region markdownBold matchgroup=markdownBoldDelimiter start="\S\@<=\*\*\|\*\*\S\@=" end="\S\@<=\*\*\|\*\*\S\@=" keepend contains=markdownLineStart,markdownItalic,@Spell' . s:concealends
|
exe 'syn region markdownBold matchgroup=markdownBoldDelimiter start="\S\@<=\*\*\|\*\*\S\@=" end="\S\@<=\*\*\|\*\*\S\@=" skip="\\\*" contains=markdownLineStart,markdownItalic,@Spell' . s:concealends
|
||||||
exe 'syn region markdownBold matchgroup=markdownBoldDelimiter start="\S\@<=__\|__\S\@=" end="\S\@<=__\|__\S\@=" keepend contains=markdownLineStart,markdownItalic,@Spell' . s:concealends
|
exe 'syn region markdownBold matchgroup=markdownBoldDelimiter start="\w\@<!__\S\@=" end="\S\@<=__\w\@!" skip="\\_" contains=markdownLineStart,markdownItalic,@Spell' . s:concealends
|
||||||
exe 'syn region markdownBoldItalic matchgroup=markdownBoldItalicDelimiter start="\S\@<=\*\*\*\|\*\*\*\S\@=" end="\S\@<=\*\*\*\|\*\*\*\S\@=" keepend contains=markdownLineStart,@Spell' . s:concealends
|
exe 'syn region markdownBoldItalic matchgroup=markdownBoldItalicDelimiter start="\S\@<=\*\*\*\|\*\*\*\S\@=" end="\S\@<=\*\*\*\|\*\*\*\S\@=" skip="\\\*" contains=markdownLineStart,@Spell' . s:concealends
|
||||||
exe 'syn region markdownBoldItalic matchgroup=markdownBoldItalicDelimiter start="\S\@<=___\|___\S\@=" end="\S\@<=___\|___\S\@=" keepend contains=markdownLineStart,@Spell' . s:concealends
|
exe 'syn region markdownBoldItalic matchgroup=markdownBoldItalicDelimiter start="\w\@<!___\S\@=" end="\S\@<=___\w\@!" skip="\\_" contains=markdownLineStart,@Spell' . s:concealends
|
||||||
|
|
||||||
syn region markdownCode matchgroup=markdownCodeDelimiter start="`" end="`" keepend contains=markdownLineStart
|
syn region markdownCode matchgroup=markdownCodeDelimiter start="`" end="`" keepend contains=markdownLineStart
|
||||||
syn region markdownCode matchgroup=markdownCodeDelimiter start="`` \=" end=" \=``" keepend contains=markdownLineStart
|
syn region markdownCode matchgroup=markdownCodeDelimiter start="`` \=" end=" \=``" keepend contains=markdownLineStart
|
||||||
syn region markdownCode matchgroup=markdownCodeDelimiter start="^\s*````*.*$" end="^\s*````*\ze\s*$" keepend
|
syn region markdownCode matchgroup=markdownCodeDelimiter start="^\s*\z(`\{3,\}\).*$" end="^\s*\z1\ze\s*$" keepend
|
||||||
|
syn region markdownCode matchgroup=markdownCodeDelimiter start="^\s*\z(\~\{3,\}\).*$" end="^\s*\z1\ze\s*$" keepend
|
||||||
|
|
||||||
syn match markdownFootnote "\[^[^\]]\+\]"
|
syn match markdownFootnote "\[^[^\]]\+\]"
|
||||||
syn match markdownFootnoteDefinition "^\[^[^\]]\+\]:"
|
syn match markdownFootnoteDefinition "^\[^[^\]]\+\]:"
|
||||||
@@ -108,7 +118,8 @@ if main_syntax ==# 'markdown'
|
|||||||
if has_key(s:done_include, matchstr(s:type,'[^.]*'))
|
if has_key(s:done_include, matchstr(s:type,'[^.]*'))
|
||||||
continue
|
continue
|
||||||
endif
|
endif
|
||||||
exe 'syn region markdownHighlight'.substitute(matchstr(s:type,'[^=]*$'),'\..*','','').' matchgroup=markdownCodeDelimiter start="^\s*````*\s*'.matchstr(s:type,'[^=]*').'\S\@!.*$" end="^\s*````*\ze\s*$" keepend contains=@markdownHighlight'.substitute(matchstr(s:type,'[^=]*$'),'\.','','g')
|
exe 'syn region markdownHighlight'.substitute(matchstr(s:type,'[^=]*$'),'\..*','','').' matchgroup=markdownCodeDelimiter start="^\s*\z(`\{3,\}\)*\s*\%({.\{-}\.\)\='.matchstr(s:type,'[^=]*').'}\=\S\@!.*$" end="^\s*\z1\ze\s*$" keepend contains=@markdownHighlight'.substitute(matchstr(s:type,'[^=]*$'),'\.','','g') . s:concealends
|
||||||
|
exe 'syn region markdownHighlight'.substitute(matchstr(s:type,'[^=]*$'),'\..*','','').' matchgroup=markdownCodeDelimiter start="^\s*\z(\~\{3,\}\)*\s*\%({.\{-}\.\)\='.matchstr(s:type,'[^=]*').'}\=\S\@!.*$" end="^\s*\z1\ze\s*$" keepend contains=@markdownHighlight'.substitute(matchstr(s:type,'[^=]*$'),'\.','','g') . s:concealends
|
||||||
let s:done_include[matchstr(s:type,'[^.]*')] = 1
|
let s:done_include[matchstr(s:type,'[^.]*')] = 1
|
||||||
endfor
|
endfor
|
||||||
unlet! s:type
|
unlet! s:type
|
||||||
|
|||||||
Reference in New Issue
Block a user