1
1
using NF . Tool . ReleaseNoteMaker . Common . Config ;
2
2
using NF . Tool . ReleaseNoteMaker . Common . Fragments ;
3
+ using SmartFormat ;
3
4
using System ;
4
5
using System . CodeDom . Compiler ;
5
6
using System . Collections . Generic ;
6
7
using System . Diagnostics . CodeAnalysis ;
7
8
using System . IO ;
8
9
using System . Linq ;
9
10
using System . Text ;
11
+ using System . Text . RegularExpressions ;
10
12
using System . Threading . Tasks ;
11
13
12
14
namespace NF . Tool . ReleaseNoteMaker . Common . Template
@@ -81,8 +83,8 @@ public sealed class TemplateRenderer
81
83
List < Content > contents = new List < Content > ( xs . Count ) ;
82
84
foreach ( Content x in xs . OrderBy ( EntryKey ) )
83
85
{
84
- List < string > formattedIssues = x . Issues . Select ( x => Issue . RenderIssue ( issueFormat , x ) ) . ToList ( ) ;
85
- string text = Issue . AppendNewlinesIfTrailingCodeBlock ( x . Text ) ;
86
+ List < string > formattedIssues = x . Issues . Select ( x => RenderIssue ( issueFormat , x ) ) . ToList ( ) ;
87
+ string text = AppendNewlinesIfTrailingCodeBlock ( x . Text ) ;
86
88
Content c = new Content ( text , formattedIssues ) ;
87
89
contents . Add ( c ) ;
88
90
}
@@ -99,7 +101,7 @@ public sealed class TemplateRenderer
99
101
string categoryDisplayName = releaseNoteTypeOrNull . DisplayName ;
100
102
{
101
103
List < string > issues = grpCategory . Select ( x => x . FragmentBasename . Issue ) . Where ( x => ! string . IsNullOrEmpty ( x ) ) . OrderBy ( IssuePart . IssueKey ) . ToList ( ) ;
102
- List < string > formattedIssues = issues . Select ( x => Issue . RenderIssue ( issueFormat , x ) ) . ToList ( ) ;
104
+ List < string > formattedIssues = issues . Select ( x => RenderIssue ( issueFormat , x ) ) . ToList ( ) ;
103
105
categories . Add ( new Category ( categoryDisplayName , contents , formattedIssues ) ) ;
104
106
}
105
107
}
@@ -222,5 +224,34 @@ internal static string TextWrap(string text, int width, string subsequentIndent)
222
224
string ret = sb . ToString ( ) . TrimEnd ( ) ;
223
225
return ret ;
224
226
}
227
+
228
+ public static string RenderIssue ( string issueFormat , string issue )
229
+ {
230
+ if ( ! string . IsNullOrEmpty ( issueFormat ) )
231
+ {
232
+ string renderedIssue = Smart . Format ( issueFormat , new { Issue = issue } ) ;
233
+ return renderedIssue ;
234
+ }
235
+
236
+ if ( int . TryParse ( issue , out int issueNumber ) )
237
+ {
238
+ string renderedIssue = $ "#{ issueNumber } ";
239
+ return renderedIssue ;
240
+ }
241
+ return issue ;
242
+ }
243
+ public static string AppendNewlinesIfTrailingCodeBlock ( string text )
244
+ {
245
+ string indentedText = @" [ \t]+[^\n]*" ;
246
+ string emptyOrIndentedTextLines = $ "(({ indentedText } )?\n )*";
247
+ string regex = @"::\n\n" + emptyOrIndentedTextLines + indentedText + "$" ;
248
+ bool isTrailingCodeBlock = Regex . IsMatch ( text , regex ) ;
249
+ if ( isTrailingCodeBlock )
250
+ {
251
+ return $ "{ text } \n \n ";
252
+ }
253
+
254
+ return text ;
255
+ }
225
256
}
226
257
}
0 commit comments