Mercurial > vim
annotate runtime/syntax/markdown.vim @ 26539:45d9468fd3f8
Added tag v8.2.3798 for changeset dfa658800f21342a8b53738625f4949c90caf105
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 13 Dec 2021 19:30:04 +0100 |
parents | 63beef1ca62c |
children | 3295247d97a5 |
rev | line source |
---|---|
2202 | 1 " Vim syntax file |
2 " Language: Markdown | |
3 " Maintainer: Tim Pope <vimNOSPAM@tpope.org> | |
4 " Filenames: *.markdown | |
19163 | 5 " Last Change: 2020 Jan 14 |
2202 | 6 |
7 if exists("b:current_syntax") | |
8 finish | |
9 endif | |
10 | |
4681
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
11 if !exists('main_syntax') |
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
12 let main_syntax = 'markdown' |
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
13 endif |
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
14 |
2202 | 15 runtime! syntax/html.vim |
16 unlet! b:current_syntax | |
17 | |
4681
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
18 if !exists('g:markdown_fenced_languages') |
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
19 let g:markdown_fenced_languages = [] |
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
20 endif |
18818 | 21 let s:done_include = {} |
4681
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
22 for s:type in map(copy(g:markdown_fenced_languages),'matchstr(v:val,"[^=]*$")') |
18818 | 23 if has_key(s:done_include, matchstr(s:type,'[^.]*')) |
24 continue | |
25 endif | |
4681
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
26 if s:type =~ '\.' |
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
27 let b:{matchstr(s:type,'[^.]*')}_subtype = matchstr(s:type,'\.\zs.*') |
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
28 endif |
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
29 exe 'syn include @markdownHighlight'.substitute(s:type,'\.','','g').' syntax/'.matchstr(s:type,'[^.]*').'.vim' |
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
30 unlet! b:current_syntax |
18818 | 31 let s:done_include[matchstr(s:type,'[^.]*')] = 1 |
4681
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
32 endfor |
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
33 unlet! s:type |
18818 | 34 unlet! s:done_include |
4681
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
35 |
18818 | 36 if !exists('g:markdown_minlines') |
37 let g:markdown_minlines = 50 | |
38 endif | |
39 execute 'syn sync minlines=' . g:markdown_minlines | |
2202 | 40 syn case ignore |
41 | |
18818 | 42 syn match markdownValid '[<>]\c[a-z/$!]\@!' transparent contains=NONE |
43 syn match markdownValid '&\%(#\=\w*;\)\@!' transparent contains=NONE | |
2202 | 44 |
4681
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
45 syn match markdownLineStart "^[<@]\@!" nextgroup=@markdownBlock,htmlSpecialChar |
2202 | 46 |
47 syn cluster markdownBlock contains=markdownH1,markdownH2,markdownH3,markdownH4,markdownH5,markdownH6,markdownBlockquote,markdownListMarker,markdownOrderedListMarker,markdownCodeBlock,markdownRule | |
18818 | 48 syn cluster markdownInline contains=markdownLineBreak,markdownLinkText,markdownItalic,markdownBold,markdownCode,markdownEscape,@htmlTop,markdownError,markdownValid |
2202 | 49 |
4681
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
50 syn match markdownH1 "^.\+\n=\+$" contained contains=@markdownInline,markdownHeadingRule,markdownAutomaticLink |
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
51 syn match markdownH2 "^.\+\n-\+$" contained contains=@markdownInline,markdownHeadingRule,markdownAutomaticLink |
2202 | 52 |
53 syn match markdownHeadingRule "^[=-]\+$" contained | |
54 | |
18818 | 55 syn region markdownH1 matchgroup=markdownH1Delimiter start="##\@!" end="#*\s*$" keepend oneline contains=@markdownInline,markdownAutomaticLink contained |
56 syn region markdownH2 matchgroup=markdownH2Delimiter start="###\@!" end="#*\s*$" keepend oneline contains=@markdownInline,markdownAutomaticLink contained | |
57 syn region markdownH3 matchgroup=markdownH3Delimiter start="####\@!" end="#*\s*$" keepend oneline contains=@markdownInline,markdownAutomaticLink contained | |
58 syn region markdownH4 matchgroup=markdownH4Delimiter start="#####\@!" end="#*\s*$" keepend oneline contains=@markdownInline,markdownAutomaticLink contained | |
59 syn region markdownH5 matchgroup=markdownH5Delimiter start="######\@!" end="#*\s*$" keepend oneline contains=@markdownInline,markdownAutomaticLink contained | |
60 syn region markdownH6 matchgroup=markdownH6Delimiter start="#######\@!" end="#*\s*$" keepend oneline contains=@markdownInline,markdownAutomaticLink contained | |
2202 | 61 |
4681
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
62 syn match markdownBlockquote ">\%(\s\|$\)" contained nextgroup=@markdownBlock |
2202 | 63 |
64 syn region markdownCodeBlock start=" \|\t" end="$" contained | |
65 | |
66 " TODO: real nesting | |
4681
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
67 syn match markdownListMarker "\%(\t\| \{0,4\}\)[-*+]\%(\s\+\S\)\@=" contained |
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
68 syn match markdownOrderedListMarker "\%(\t\| \{0,4}\)\<\d\+\.\%(\s\+\S\)\@=" contained |
2202 | 69 |
70 syn match markdownRule "\* *\* *\*[ *]*$" contained | |
71 syn match markdownRule "- *- *-[ -]*$" contained | |
72 | |
4681
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
73 syn match markdownLineBreak " \{2,\}$" |
2202 | 74 |
75 syn region markdownIdDeclaration matchgroup=markdownLinkDelimiter start="^ \{0,3\}!\=\[" end="\]:" oneline keepend nextgroup=markdownUrl skipwhite | |
76 syn match markdownUrl "\S\+" nextgroup=markdownUrlTitle skipwhite contained | |
77 syn region markdownUrl matchgroup=markdownUrlDelimiter start="<" end=">" oneline keepend nextgroup=markdownUrlTitle skipwhite contained | |
78 syn region markdownUrlTitle matchgroup=markdownUrlTitleDelimiter start=+"+ end=+"+ keepend contained | |
79 syn region markdownUrlTitle matchgroup=markdownUrlTitleDelimiter start=+'+ end=+'+ keepend contained | |
80 syn region markdownUrlTitle matchgroup=markdownUrlTitleDelimiter start=+(+ end=+)+ keepend contained | |
81 | |
18818 | 82 syn region markdownLinkText matchgroup=markdownLinkTextDelimiter start="!\=\[\%(\%(\_[^][]\|\[\_[^][]*\]\)*]\%( \=[[(]\)\)\@=" end="\]\%( \=[[(]\)\@=" nextgroup=markdownLink,markdownId skipwhite contains=@markdownInline,markdownLineStart |
2202 | 83 syn region markdownLink matchgroup=markdownLinkDelimiter start="(" end=")" contains=markdownUrl keepend contained |
84 syn region markdownId matchgroup=markdownIdDelimiter start="\[" end="\]" keepend contained | |
85 syn region markdownAutomaticLink matchgroup=markdownUrlDelimiter start="<\%(\w\+:\|[[:alnum:]_+-]\+@\)\@=" end=">" keepend oneline | |
86 | |
18818 | 87 let s:concealends = '' |
88 if has('conceal') && get(g:, 'markdown_syntax_conceal', 1) == 1 | |
89 let s:concealends = ' concealends' | |
90 endif | |
19163 | 91 exe 'syn region markdownItalic matchgroup=markdownItalicDelimiter start="\S\@<=\*\|\*\S\@=" end="\S\@<=\*\|\*\S\@=" skip="\\\*" contains=markdownLineStart,@Spell' . s:concealends |
18818 | 92 exe 'syn region markdownItalic matchgroup=markdownItalicDelimiter start="\w\@<!_\S\@=" end="\S\@<=_\w\@!" skip="\\_" contains=markdownLineStart,@Spell' . s:concealends |
19163 | 93 exe 'syn region markdownBold matchgroup=markdownBoldDelimiter start="\S\@<=\*\*\|\*\*\S\@=" end="\S\@<=\*\*\|\*\*\S\@=" skip="\\\*" contains=markdownLineStart,markdownItalic,@Spell' . s:concealends |
18818 | 94 exe 'syn region markdownBold matchgroup=markdownBoldDelimiter start="\w\@<!__\S\@=" end="\S\@<=__\w\@!" skip="\\_" contains=markdownLineStart,markdownItalic,@Spell' . s:concealends |
19163 | 95 exe 'syn region markdownBoldItalic matchgroup=markdownBoldItalicDelimiter start="\S\@<=\*\*\*\|\*\*\*\S\@=" end="\S\@<=\*\*\*\|\*\*\*\S\@=" skip="\\\*" contains=markdownLineStart,@Spell' . s:concealends |
18818 | 96 exe 'syn region markdownBoldItalic matchgroup=markdownBoldItalicDelimiter start="\w\@<!___\S\@=" end="\S\@<=___\w\@!" skip="\\_" contains=markdownLineStart,@Spell' . s:concealends |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
97 |
4681
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
98 syn region markdownCode matchgroup=markdownCodeDelimiter start="`" end="`" keepend contains=markdownLineStart |
2202 | 99 syn region markdownCode matchgroup=markdownCodeDelimiter start="`` \=" end=" \=``" keepend contains=markdownLineStart |
18818 | 100 syn region markdownCode matchgroup=markdownCodeDelimiter start="^\s*````*.*$" end="^\s*````*\ze\s*$" keepend |
4681
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
101 |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
102 syn match markdownFootnote "\[^[^\]]\+\]" |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
103 syn match markdownFootnoteDefinition "^\[^[^\]]\+\]:" |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
104 |
4681
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
105 if main_syntax ==# 'markdown' |
18818 | 106 let s:done_include = {} |
4681
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
107 for s:type in g:markdown_fenced_languages |
18818 | 108 if has_key(s:done_include, matchstr(s:type,'[^.]*')) |
109 continue | |
110 endif | |
111 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') . s:concealends | |
112 let s:done_include[matchstr(s:type,'[^.]*')] = 1 | |
4681
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
113 endfor |
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
114 unlet! s:type |
18818 | 115 unlet! s:done_include |
4681
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
116 endif |
2202 | 117 |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
118 syn match markdownEscape "\\[][\\`*_{}()<>#+.!-]" |
4681
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
119 syn match markdownError "\w\@<=_\w\@=" |
2202 | 120 |
121 hi def link markdownH1 htmlH1 | |
122 hi def link markdownH2 htmlH2 | |
123 hi def link markdownH3 htmlH3 | |
124 hi def link markdownH4 htmlH4 | |
125 hi def link markdownH5 htmlH5 | |
126 hi def link markdownH6 htmlH6 | |
127 hi def link markdownHeadingRule markdownRule | |
18818 | 128 hi def link markdownH1Delimiter markdownHeadingDelimiter |
129 hi def link markdownH2Delimiter markdownHeadingDelimiter | |
130 hi def link markdownH3Delimiter markdownHeadingDelimiter | |
131 hi def link markdownH4Delimiter markdownHeadingDelimiter | |
132 hi def link markdownH5Delimiter markdownHeadingDelimiter | |
133 hi def link markdownH6Delimiter markdownHeadingDelimiter | |
2202 | 134 hi def link markdownHeadingDelimiter Delimiter |
135 hi def link markdownOrderedListMarker markdownListMarker | |
136 hi def link markdownListMarker htmlTagName | |
137 hi def link markdownBlockquote Comment | |
138 hi def link markdownRule PreProc | |
139 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
140 hi def link markdownFootnote Typedef |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
141 hi def link markdownFootnoteDefinition Typedef |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
142 |
2202 | 143 hi def link markdownLinkText htmlLink |
144 hi def link markdownIdDeclaration Typedef | |
145 hi def link markdownId Type | |
146 hi def link markdownAutomaticLink markdownUrl | |
147 hi def link markdownUrl Float | |
148 hi def link markdownUrlTitle String | |
149 hi def link markdownIdDelimiter markdownLinkDelimiter | |
150 hi def link markdownUrlDelimiter htmlTag | |
151 hi def link markdownUrlTitleDelimiter Delimiter | |
152 | |
153 hi def link markdownItalic htmlItalic | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
154 hi def link markdownItalicDelimiter markdownItalic |
2202 | 155 hi def link markdownBold htmlBold |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
156 hi def link markdownBoldDelimiter markdownBold |
2202 | 157 hi def link markdownBoldItalic htmlBoldItalic |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
158 hi def link markdownBoldItalicDelimiter markdownBoldItalic |
2202 | 159 hi def link markdownCodeDelimiter Delimiter |
160 | |
161 hi def link markdownEscape Special | |
4681
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
162 hi def link markdownError Error |
2202 | 163 |
164 let b:current_syntax = "markdown" | |
4681
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
165 if main_syntax ==# 'markdown' |
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
166 unlet main_syntax |
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2202
diff
changeset
|
167 endif |
2202 | 168 |
169 " vim:set sw=2: |