@@ -39,6 +39,9 @@ private static string BulletList(IEnumerable<string> items) =>
3939 private static string Heading ( string title , int level = 2 ) =>
4040 $ "{ new string ( '#' , level ) } { title } ";
4141
42+ public static string Render ( string content , DocsFormat format ) =>
43+ format == DocsFormat . Markdown ? content : RenderPlainText ( content ) ;
44+
4245 public static readonly Dictionary < HelpOption , Func < string > > GeneralOptions = new ( )
4346 {
4447 [ HelpOption . Start ] = GetStartHelpPage ,
@@ -52,7 +55,18 @@ private static string Heading(string title, int level = 2) =>
5255 [ HelpOption . Keywords ] = GetKeywordHelpPage
5356 } ;
5457
55- public static bool GetGeneralOutput ( ArraySegment < string > args , ICommandSender sender , out string response )
58+ public static bool GetGeneralOutput (
59+ ArraySegment < string > args ,
60+ ICommandSender sender ,
61+ out string response ,
62+ DocsFormat format = DocsFormat . Markdown )
63+ {
64+ var result = GetGeneralOutputMarkdown ( args , sender , out var markdownResponse ) ;
65+ response = Render ( markdownResponse , format ) ;
66+ return result ;
67+ }
68+
69+ private static bool GetGeneralOutputMarkdown ( ArraySegment < string > args , ICommandSender sender , out string response )
5670 {
5771 var arg = args . Array ? [ args . Offset ] . ToLowerInvariant ( )
5872 ?? throw new CoreInvariantException ( "Help arguments were provided in an invalid format." ) ;
@@ -141,7 +155,12 @@ public static bool GetGeneralOutput(ArraySegment<string> args, ICommandSender se
141155 return false ;
142156 }
143157
144- public static string GetOptionsList ( )
158+ public static string GetOptionsList ( DocsFormat format = DocsFormat . Markdown )
159+ {
160+ return Render ( GetOptionsListMarkdown ( ) , format ) ;
161+ }
162+
163+ private static string GetOptionsListMarkdown ( )
145164 {
146165 return $ """
147166 # SER help
@@ -338,7 +357,7 @@ public static string GetKeywordInfo(IKeywordContext keyword)
338357 public static string GetKeywordHelpPage ( )
339358 {
340359 return
341- """
360+ $ """
342361 Keywords alter how the script behaves, not by changing someones role, but the internal script execution.
343362 They can range from simple things from stopping the script to handling advanced logic.
344363
@@ -1028,6 +1047,61 @@ public static bool GetPropertiesForType(string typeName, out string response)
10281047 return true ;
10291048 }
10301049
1050+ private static string RenderPlainText ( string content )
1051+ {
1052+ var lines = content . Replace ( "\r \n " , "\n " ) . Replace ( '\r ' , '\n ' ) . Split ( '\n ' ) ;
1053+ var output = new StringBuilder ( ) ;
1054+ var inCodeBlock = false ;
1055+
1056+ for ( var index = 0 ; index < lines . Length ; index ++ )
1057+ {
1058+ var line = lines [ index ] ;
1059+ var trimmed = line . Trim ( ) ;
1060+
1061+ if ( trimmed . StartsWith ( "```" , StringComparison . Ordinal ) )
1062+ {
1063+ inCodeBlock = ! inCodeBlock ;
1064+ continue ;
1065+ }
1066+
1067+ if ( inCodeBlock )
1068+ {
1069+ output . AppendLine ( line ) ;
1070+ continue ;
1071+ }
1072+
1073+ if ( trimmed . Length == 0 )
1074+ {
1075+ output . AppendLine ( ) ;
1076+ continue ;
1077+ }
1078+
1079+ var heading = trimmed . TakeWhile ( c => c == '#' ) . Count ( ) ;
1080+ if ( heading is > 0 and <= 6 && trimmed . Length > heading && char . IsWhiteSpace ( trimmed [ heading ] ) )
1081+ {
1082+ var title = StripInlineMarkdown ( trimmed [ ( heading + 1 ) ..] . Trim ( ) ) ;
1083+ output . AppendLine ( title ) ;
1084+ output . AppendLine ( new string ( heading == 1 ? '=' : '-' , Math . Max ( 3 , title . Length ) ) ) ;
1085+ continue ;
1086+ }
1087+
1088+ output . AppendLine ( StripInlineMarkdown ( line ) ) ;
1089+ }
1090+
1091+ return output . ToString ( ) . TrimEnd ( ) ;
1092+ }
1093+
1094+ private static string StripInlineMarkdown ( string line )
1095+ {
1096+ line = line . Replace ( "\\ `" , "`" ) ;
1097+ line = System . Text . RegularExpressions . Regex . Replace ( line , @"`([^`]*)`" , "$1" ) ;
1098+ line = System . Text . RegularExpressions . Regex . Replace ( line , @"\[([^\]]+)\]\([^\)]+\)" , "$1" ) ;
1099+ line = line . Replace ( "**" , string . Empty ) . Replace ( "__" , string . Empty ) ;
1100+ line = System . Text . RegularExpressions . Regex . Replace ( line , @"(?<!\w)[*_](.*?)[*_](?!\w)" , "$1" ) ;
1101+ line = System . Text . RegularExpressions . Regex . Replace ( line , @"^\s*>\s?" , "" ) ;
1102+ return line ;
1103+ }
1104+
10311105 // ai
10321106 public static bool GetPropertiesAdvanced (
10331107 ArraySegment < string > args ,
0 commit comments