-
-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #638 from mnaoumov/issue-579
Add YamlFrontMatterRoundtripRenderer
- Loading branch information
Showing
5 changed files
with
59 additions
and
5 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/Markdig.Tests/RoundtripSpecs/TestYamlFrontMatterBlock.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Markdig.Renderers.Roundtrip; | ||
using Markdig.Syntax; | ||
using NUnit.Framework; | ||
using static Markdig.Tests.TestRoundtrip; | ||
|
||
namespace Markdig.Tests.RoundtripSpecs | ||
{ | ||
[TestFixture] | ||
public class TestYamlFrontMatterBlock | ||
{ | ||
[TestCase("---\nkey1: value1\nkey2: value2\n---\n\nContent\n")] | ||
[TestCase("No front matter")] | ||
[TestCase("Looks like front matter but actually is not\n---\nkey1: value1\nkey2: value2\n---")] | ||
public void FrontMatterBlockIsPreserved(string value) | ||
{ | ||
RoundTrip(value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/Markdig/Extensions/Yaml/YamlFrontMatterRoundtripRenderer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) Alexandre Mutel. All rights reserved. | ||
// This file is licensed under the BSD-Clause 2 license. | ||
// See the license.txt file in the project root for more information. | ||
|
||
using System; | ||
using Markdig.Renderers; | ||
using Markdig.Renderers.Roundtrip; | ||
|
||
namespace Markdig.Extensions.Yaml | ||
{ | ||
public class YamlFrontMatterRoundtripRenderer : MarkdownObjectRenderer<RoundtripRenderer, YamlFrontMatterBlock> | ||
{ | ||
private readonly CodeBlockRenderer _codeBlockRenderer; | ||
|
||
public YamlFrontMatterRoundtripRenderer() | ||
{ | ||
_codeBlockRenderer = new CodeBlockRenderer(); | ||
} | ||
|
||
protected override void Write(RoundtripRenderer renderer, YamlFrontMatterBlock obj) | ||
{ | ||
renderer.Writer.WriteLine("---"); | ||
_codeBlockRenderer.Write(renderer, obj); | ||
renderer.Writer.WriteLine("---"); | ||
} | ||
} | ||
} |