File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 6161# End Region
6262
6363Imports System.Text.RegularExpressions
64+ Imports Microsoft.VisualBasic.ComponentModel.DataSourceModel
6465Imports Microsoft.VisualBasic.Linq
6566Imports Microsoft.VisualBasic.Text
6667
@@ -364,6 +365,19 @@ Public Class MarkdownRender
364365 ReadOnly h2 As New Regex( "^[#]{2}.+$" , RegexOptions.Compiled Or RegexOptions.Multiline)
365366 ReadOnly h1 As New Regex( "^[#]{1}.+$" , RegexOptions.Compiled Or RegexOptions.Multiline)
366367
368+ Shared ReadOnly headers As New Regex( "^[#]+.+$" , RegexOptions.Compiled Or RegexOptions.Multiline)
369+
370+ ''' <summary>
371+ ''' parse TOC from markdown document
372+ ''' </summary>
373+ ''' <param name="md"></param>
374+ ''' <returns></returns>
375+ Public Shared Iterator Function GetTOC(md As String ) As IEnumerable( Of NamedValue( Of Integer ))
376+ For Each level As String In headers.Matches(md).ToArray
377+ Yield New NamedValue( Of Integer )(level.Trim( " "c , "#"c ), level.TakeWhile( Function (c) c = "#"c ).Count)
378+ Next
379+ End Function
380+
367381 Private Sub RunHeader()
368382 text = h6.Replace(text, Function (m) vbLf & render.Header(TrimHeader(m.Value), 6 ) & vbLf)
369383 text = h5.Replace(text, Function (m) vbLf & render.Header(TrimHeader(m.Value), 5 ) & vbLf)
You can’t perform that action at this time.
0 commit comments