Skip to content

Commit

Permalink
introduced CODE-EXAMPLE block
Browse files Browse the repository at this point in the history
  • Loading branch information
ppekrol committed Aug 1, 2024
1 parent 2196790 commit f67be95
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions Raven.Documentation.Parser/DocumentBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public string Build(FolderItem page)
{
_content = NoteBlockHelper.GenerateNoteBlocks(_content);
_content = PanelBlockHelper.GeneratePanelBlocks(_content);
_content = CodeBlockHelper.GenerateCodeExamples(_content);
}

if (_codeBlocks != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class CodeBlockHelper

private static readonly Regex CodeTabBlockFinder = new Regex(@"{CODE-TAB-BLOCK:(.+?)}(.*?){CODE-TAB-BLOCK/}", RegexOptions.Compiled | RegexOptions.Singleline);

private static readonly Regex CodeExampleFinder = new Regex(@"{CODE-EXAMPLE:(.+?)}(.*?){CODE-EXAMPLE/}", RegexOptions.Compiled | RegexOptions.Singleline);

private static readonly Regex FirstLineSpacesFinder = new Regex(@"^(\s|\t)+", RegexOptions.Compiled);

public static string ReplaceCodeBlocksWithPlaceholders(string content, out IDictionary<string, string> placeholders)
Expand Down Expand Up @@ -100,6 +102,27 @@ public static string GenerateCodeBlocks(string content, string documentationVers
return content;
}

public static string GenerateCodeExamples(string content)
{
content = CodeExampleFinder.Replace(content, match => GenerateCodeExample(match.Groups[1].Value.Trim(), match.Groups[2].Value.Trim()));

return content;
}

private static string GenerateCodeExample(string title, string content)
{
content = NormalizeContent(content);

var builder = new StringBuilder();
builder.AppendLine("<div class='code-example'>");
if (string.IsNullOrWhiteSpace(title) == false)
builder.AppendLine($"<h4>{title}</h4>");

builder.AppendLine(content);
builder.AppendLine("</div>");
return builder.ToString();
}

private static string GenerateCodeBlock(string languageAsString, string content, IDictionary<string, string> placeholders)
{
var language = (CodeBlockLanguage)Enum.Parse(typeof(CodeBlockLanguage), languageAsString, true);
Expand Down
2 changes: 1 addition & 1 deletion Raven.Documentation.Web.Core/ViewModels/Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static List<float> AllVersionsAsFloat
}
}

public const string Default = "5.0";
public const string Default = "6.0";

public enum DocsMode
{
Expand Down

0 comments on commit f67be95

Please sign in to comment.