9
9
// </summary>
10
10
// -----------------------------------------------------------------------
11
11
12
+ using System ;
13
+ using System . Collections . Generic ;
12
14
using System . IO ;
13
15
using System . Linq ;
14
16
using System . Reflection ;
15
17
using NUnit . Framework ;
18
+ using Shrinker . Lexer ;
16
19
17
20
namespace UnitTests
18
21
{
@@ -32,17 +35,22 @@ public void BuildTheReadme()
32
35
var readmeLines = File . ReadAllLines ( readmeFile . FullName ) . TakeWhile ( o => ! o . StartsWith ( "# Features" ) ) . ToList ( ) ;
33
36
readmeLines . Add ( "# Features" ) ;
34
37
38
+ var tocIndex = readmeLines . Count ;
39
+ var toc = new List < string > ( ) ;
40
+
35
41
// Find options XAML.
36
42
var optionsXamlFile = rootDir . EnumerateFiles ( "OptionsDialog.xaml" , SearchOption . AllDirectories ) . FirstOrDefault ( ) ;
37
43
Assert . That ( optionsXamlFile , Is . Not . Null ) ;
38
44
39
45
// Read all the Markdown tooltip content.
40
46
var inTooltip = false ;
47
+ var indent = 0 ;
41
48
foreach ( var xamlLine in File . ReadAllLines ( optionsXamlFile . FullName ) )
42
49
{
43
50
if ( xamlLine . Contains ( "<MdXaml:MarkdownScrollViewer" ) )
44
51
{
45
52
inTooltip = true ;
53
+ indent = xamlLine . IndexOf ( '<' ) + 4 ;
46
54
}
47
55
else if ( xamlLine . Contains ( "</MdXaml:MarkdownScrollViewer" ) )
48
56
{
@@ -52,10 +60,33 @@ public void BuildTheReadme()
52
60
}
53
61
54
62
if ( inTooltip && ! xamlLine . TrimStart ( ) . StartsWith ( "<" ) )
55
- readmeLines . Add ( xamlLine . Trim ( ) ) ;
63
+ {
64
+ var mdLine = xamlLine
65
+ . Substring ( Math . Min ( xamlLine . Length , indent ) )
66
+ . TrimEnd ( )
67
+ . Replace ( "```c" , "```glsl" ) ;
68
+
69
+ if ( xamlLine . TrimStart ( ) . StartsWith ( "### " ) )
70
+ {
71
+ // Build 'features' TOC.
72
+ var heading = xamlLine . Trim ( ' ' , '#' ) ;
73
+ toc . Add ( $ "* [{ heading } ](#{ ToHeaderLink ( heading ) } )") ;
74
+
75
+ mdLine = mdLine . Replace ( "### " , "## " ) ; // Elevate the header level one-above what we use in the XAML.
76
+ }
77
+
78
+ readmeLines . Add ( mdLine ) ;
79
+ }
56
80
}
57
81
82
+ readmeLines . InsertRange ( tocIndex , toc ) ;
58
83
File . WriteAllLines ( readmeFile . FullName , readmeLines ) ;
59
84
}
85
+
86
+ private static string ToHeaderLink ( string s )
87
+ {
88
+ s = s . Replace ( ' ' , '-' ) ;
89
+ return s . ToLower ( ) ;
90
+ }
60
91
}
61
92
}
0 commit comments