Пример #1
0
        public void ExtractMetadataFromPostTest(string markdown)
        {
            var result = _markdownService.GetPostMetadataFromMarkDown(markdown);

            Console.WriteLine(result);
            Assert.True(result.Equals(" Hello World "));
        }
Пример #2
0
 public Post GeneratePostWithPostInfo(string postContent)
 {
     try{
         Post post         = new Post();
         var  deserializer = new DeserializerBuilder().WithNamingConvention(CamelCaseNamingConvention.Instance).Build();
         var  yaml         = _markdownService.GetPostMetadataFromMarkDown(postContent);
         post.postAsMarkdown = postContent;
         postContent         = postContent.Replace("---" + yaml + "---", "");
         post.postInfo       = deserializer.Deserialize <PostInfo>(yaml);
         post.postAsHtml     = _markdownService.ParseMarkDownToHtml(postContent);
         StringBuilder sb = new StringBuilder();
         sb.AppendLine("Generated post wih :");
         sb.AppendLine($"PostAsMarkDown : {post.Stringify(post)}");
         sb.AppendLine($"PostInfo :{yaml} {post.Stringify(post.postInfo)}");
         _logger.LogDebug(sb.ToString());
         return(post);
     }
     catch (Exception e)
     {
         _logger.LogError($"Failed to generate post. {e.Message} ", e);
         throw e;
     }
 }