@@ -7,8 +7,8 @@ if !exists("g:vmt_auto_update_on_save")
7
7
let g: vmt_auto_update_on_save = 1
8
8
endif
9
9
10
- if ! exists (" g:vmt_dont_insert_marker " )
11
- let g: vmt_dont_insert_marker = 0
10
+ if ! exists (" g:vmt_dont_insert_fence " )
11
+ let g: vmt_dont_insert_fence = 0
12
12
endif
13
13
14
14
let g: GFMHeadingIds = {}
@@ -162,8 +162,8 @@ function! s:GenToc(markdownStyle)
162
162
163
163
let l: minLevel = min (l: levels )
164
164
165
- if g: vmt_dont_insert_marker == 0
166
- put = <SID> GetBeginMarker (a: markdownStyle )
165
+ if g: vmt_dont_insert_fence == 0
166
+ put = <SID> GetBeginFence (a: markdownStyle )
167
167
endif
168
168
169
169
let l: i = 0
@@ -185,36 +185,39 @@ function! s:GenToc(markdownStyle)
185
185
" a blank line after toc to avoid effect typo of content below
186
186
put = ' '
187
187
188
- if g: vmt_dont_insert_marker == 0
189
- put = <SID> GetEndMarker ()
188
+ if g: vmt_dont_insert_fence == 0
189
+ put = <SID> GetEndFence ()
190
190
endif
191
191
endfunction
192
192
193
- function ! s: GetBeginMarker (markdownStyle)
193
+ function ! s: GetBeginFence (markdownStyle)
194
194
return " <!-- vim-markdown-toc " . a: markdownStyle . " -->"
195
195
endfunction
196
196
197
- function ! s: GetEndMarker ()
197
+ function ! s: GetEndFence ()
198
198
return " <!-- vim-markdown-toc -->"
199
199
endfunction
200
200
201
- function ! s: GetBeginMarkerPattern ()
201
+ function ! s: GetBeginFencePattern ()
202
202
return " <!-- vim-markdown-toc \\ ([[:alpha:]]\\ +\\ ) -->"
203
203
endfunction
204
204
205
- function ! s: GetEndMarkerPattern ()
206
- return <SID> GetEndMarker ()
205
+ function ! s: GetEndFencePattern ()
206
+ return <SID> GetEndFence ()
207
207
endfunction
208
208
209
209
function ! s: UpdateToc ()
210
210
let l: winview = winsaveview ()
211
211
212
212
let l: totalLineNum = line (" $" )
213
213
214
- let l: markdownStyle = <SID> GetExistsTocStyle ()
214
+ let [ l: markdownStyle, l: beginLineNumber , l: endLineNumber ] = <SID> DeleteExistingToc ()
215
215
216
- if l: markdownStyle != " "
217
- let [l: beginLineNumber ,l: endLineNumber ] = <SID> DeleteExistsToc ()
216
+ if l: markdownStyle == # " "
217
+ echoe " Cannot find existing toc"
218
+ elseif l: markdownStyle == # " Unknown"
219
+ echoe " Find unsupported style toc"
220
+ else
218
221
let l: isFirstLine = (l: beginLineNumber == 1 )
219
222
if l: beginLineNumber > 1
220
223
let l: beginLineNumber -= 1
@@ -239,68 +242,46 @@ function! s:UpdateToc()
239
242
let l: winview [' lnum' ] += l: diff
240
243
let l: winview [' topline' ] += l: diff
241
244
endif
242
- else
243
- echoe " Cannot find existing toc"
244
245
endif
245
246
246
247
call winrestview (l: winview )
247
248
endfunction
248
249
249
- function ! s: DeleteExistsToc ()
250
+ function ! s: DeleteExistingToc ()
250
251
let l: winview = winsaveview ()
251
252
252
253
normal ! gg
253
254
254
- let l: tocBeginPattern = <SID> GetBeginMarkerPattern ()
255
- let l: tocEndPattern = <SID> GetEndMarkerPattern ()
255
+ let l: tocBeginPattern = <SID> GetBeginFencePattern ()
256
+ let l: tocEndPattern = <SID> GetEndFencePattern ()
256
257
258
+ let l: markdownStyle = " "
257
259
let l: beginLineNumber = -1
258
260
let l: endLineNumber= -1
259
261
260
262
let l: flags = " Wc"
261
263
if search (l: tocBeginPattern , l: flags ) != 0
264
+ let l: beginLine = getline (" ." )
262
265
let l: beginLineNumber = line (" ." )
263
266
264
267
if search (l: tocEndPattern , l: flags ) != 0
265
- let l: endLineNumber = line (" ." )
266
- execute l: beginLineNumber . " ," . l: endLineNumber . " delete_"
267
- else
268
- echoe " Cannot find toc end marker"
269
- let l: beginLineNumber = -1
270
- endif
271
- endif
272
-
273
- call winrestview (l: winview )
274
-
275
- return [l: beginLineNumber ,l: endLineNumber ]
276
- endfunction
277
-
278
- function ! s: GetExistsTocStyle ()
279
- let l: winview = winsaveview ()
280
-
281
- normal ! gg
282
-
283
- let l: markdownStyle = " "
284
-
285
- let l: tocBeginPattern = <SID> GetBeginMarkerPattern ()
286
- let l: tocEndPattern = <SID> GetEndMarkerPattern ()
287
-
288
- let l: flags = " Wc"
289
- if search (l: tocBeginPattern , l: flags ) != 0
290
- let l: line = getline (" ." )
291
-
292
- if search (l: tocEndPattern , l: flags ) != 0
293
- let l: markdownStyle = matchlist (l: line , l: tocBeginPattern )[1 ]
268
+ let l: markdownStyle = matchlist (l: beginLine , l: tocBeginPattern )[1 ]
294
269
if l: markdownStyle != " GFM" && l: markdownStyle != " Redcarpet"
295
- echoe " Find unsupported markdown style"
296
- let l: markdownStyle = " "
270
+ let l: markdownStyle = " Unknown"
271
+ else
272
+ let l: endLineNumber = line (" ." )
273
+ execute l: beginLineNumber . " ," . l: endLineNumber . " delete_"
297
274
end
275
+ else
276
+ echoe " Cannot find toc end fence"
298
277
endif
278
+ else
279
+ echoe " Cannot find toc begin fence"
299
280
endif
300
281
301
282
call winrestview (l: winview )
302
283
303
- return l: markdownStyle
284
+ return [ l: markdownStyle, l: beginLineNumber , l: endLineNumber ]
304
285
endfunction
305
286
306
287
command ! GenTocGFM :call <SID> GenToc (" GFM" )
0 commit comments