Front matters
This commit is contained in:
parent
514549c5f9
commit
4034c39905
6 changed files with 215 additions and 12 deletions
|
|
@ -0,0 +1,8 @@
|
|||
namespace Yavsc.Server.Models.Billing;
|
||||
|
||||
public class FrontmatterOffreResult
|
||||
{
|
||||
public string Formulaire { get; set; }
|
||||
public string Devis { get; set; }
|
||||
public string Corps { get; set; } // le Markdown sans l'en-tête
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
|
||||
|
||||
class ChatBilling {
|
||||
|
||||
}
|
||||
32
src/Yavsc.Server/Services/FrontmatterParser.cs
Normal file
32
src/Yavsc.Server/Services/FrontmatterParser.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
using YamlDotNet.Serialization;
|
||||
using YamlDotNet.Serialization.NamingConventions;
|
||||
using Yavsc.Server.Models.Billing;
|
||||
|
||||
namespace Yavsc.Server.Services;
|
||||
|
||||
public static class FrontmatterParser
|
||||
{
|
||||
public const string YamlSeparator = "---";
|
||||
|
||||
private static readonly IDeserializer _deserializer =
|
||||
new DeserializerBuilder()
|
||||
.WithNamingConvention(CamelCaseNamingConvention.Instance)
|
||||
.IgnoreUnmatchedProperties()
|
||||
.Build();
|
||||
|
||||
public static FrontmatterOffreResult Parse(string markdown)
|
||||
{
|
||||
// Le contenu doit commencer par ----
|
||||
if (!markdown.TrimStart().StartsWith(YamlSeparator))
|
||||
return new FrontmatterOffreResult { Corps = markdown };
|
||||
var parts = markdown.TrimStart()[3..].Split(new[] { "\n"+YamlSeparator }, 2,
|
||||
StringSplitOptions.None);
|
||||
if (parts.Length < 2)
|
||||
return new FrontmatterOffreResult { Corps = markdown };
|
||||
var yamlBlock = parts[0].Trim();
|
||||
var corps = parts[1].Trim();
|
||||
var meta = _deserializer.Deserialize<FrontmatterOffreResult>(yamlBlock);
|
||||
meta.Corps = corps;
|
||||
return meta;
|
||||
}
|
||||
}
|
||||
|
|
@ -31,8 +31,9 @@
|
|||
<PackageReference Include="MailKit" />
|
||||
<PackageReference Include="MimeKit" />
|
||||
<PackageReference Include="pazof.rules" />
|
||||
<PackageReference Include="YamlDotNet" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../Yavsc.Abstract/Yavsc.Abstract.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue