File tree Expand file tree Collapse file tree 4 files changed +51
-30
lines changed Expand file tree Collapse file tree 4 files changed +51
-30
lines changed Original file line number Diff line number Diff line change @@ -10,8 +10,8 @@ A vim plugin to generate table of contents for Markdown files.
1010* [ Features] ( #features )
1111* [ Installation] ( #installation )
1212* [ Usage] ( #usage )
13- * [Generate table of contents](#generate-table-of-contents)
14- * [Update existing table of contents](#update-existing-table-of-contents)
13+ * [ Generate table of contents] ( #generate-table-of-contents )
14+ * [ Update existing table of contents] ( #update-existing-table-of-contents )
1515* [ Options] ( #options )
1616* [ Screenshots] ( #screenshots )
1717* [ References] ( #references )
Original file line number Diff line number Diff line change 1414let g: GFMHeadingIds = {}
1515
1616function ! s: HeadingLineRegex ()
17- return " ^[#] \\ {1,6}"
17+ return ' \v(^.+$\n\=+|^.+$\n\-+|^# {1,6}) '
1818endfunction
1919
2020function ! s: GetSections (beginRegex, endRegex)
@@ -54,8 +54,8 @@ endfunction
5454
5555function ! s: IsLineInCodeSections (codeSections, lineNum)
5656 for beginLine in keys (a: codeSections )
57- if a: lineNum > str2nr (beginLine)
58- if a: lineNum < a: codeSections [beginLine]
57+ if a: lineNum >= str2nr (beginLine)
58+ if a: lineNum <= a: codeSections [beginLine]
5959 return 1
6060 endif
6161 endif
@@ -76,6 +76,15 @@ function! s:GetHeadingLines()
7676 let l: line = getline (" ." )
7777 let l: lineNum = line (" ." )
7878 if <SID> IsLineInCodeSections (l: codeSections , l: lineNum ) == 0
79+ " === compatible with Setext Style headings
80+ let l: nextLine = getline (l: lineNum + 1 )
81+ if matchstr (l: nextLine , ' \v^\=+$' ) != " "
82+ let l: line = " # " . l: line
83+ elseif matchstr (l: nextLine , ' \v^\-+$' ) != " "
84+ let l: line = " ## " . l: line
85+ endif
86+ " ===
87+
7988 call add (l: headingLines , l: line )
8089 endif
8190 endwhile
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+
2+ <!-- vim-markdown-toc GFM -->
3+ * [ heading1] ( #heading1 )
4+ * [ heading2] ( #heading2 )
5+ * [ chapter 1] ( #chapter-1 )
6+ * [ chapter two] ( #chapter-------two )
7+ * [ 第三章!] ( #第三章 )
8+ * [ heading without space behind hashes] ( #heading-without-space-behind-hashes )
9+ * [ heading with trailing hashes] ( #heading-with-trailing-hashes )
10+ * [ heading with trailing hashes nested with spaces #] ( #heading-with-trailing-hashes-nested-with-spaces- )
11+ * [ heading with trailing hashes nested with spaces # #] ( #heading-with-trailing-hashes-nested-with-spaces-- )
12+
13+ <!-- vim-markdown-toc -->
14+
15+ heading1
16+ ===
17+
18+ heading2
19+ --
20+
21+ ===
22+
23+ ---
24+
25+ # chapter 1
26+
27+ # chapter two
28+
29+ # 第三章!
30+
31+ ##heading without space behind hashes
32+
33+ ## heading with trailing hashes ##
34+
35+ ## heading with trailing hashes nested with spaces # #
36+
37+ ## heading with trailing hashes nested with spaces # #
You can’t perform that action at this time.
0 commit comments