-
Notifications
You must be signed in to change notification settings - Fork 868
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: multiple overwrite sections using markdig (#8457)
- Loading branch information
Showing
26 changed files
with
218 additions
and
248 deletions.
There are no files selected for viewing
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
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
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
98 changes: 49 additions & 49 deletions
98
src/Microsoft.DocAsCode.MarkdigEngine/YamlHeader/YamlHeaderRenderer.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 |
---|---|---|
@@ -1,52 +1,52 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.DocAsCode.MarkdigEngine.Extensions | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Net; | ||
|
||
using Markdig.Extensions.Yaml; | ||
using Markdig.Renderers; | ||
using Markdig.Renderers.Html; | ||
using Microsoft.DocAsCode.Common; | ||
|
||
public class YamlHeaderRenderer : HtmlObjectRenderer<YamlFrontMatterBlock> | ||
{ | ||
private readonly MarkdownContext _context; | ||
|
||
public YamlHeaderRenderer(MarkdownContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
protected override void Write(HtmlRenderer renderer, YamlFrontMatterBlock obj) | ||
{ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.DocAsCode.MarkdigEngine.Extensions | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Net; | ||
|
||
using Markdig.Extensions.Yaml; | ||
using Markdig.Renderers; | ||
using Markdig.Renderers.Html; | ||
using Microsoft.DocAsCode.Common; | ||
|
||
public class YamlHeaderRenderer : HtmlObjectRenderer<YamlFrontMatterBlock> | ||
{ | ||
private readonly MarkdownContext _context; | ||
|
||
public YamlHeaderRenderer(MarkdownContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
protected override void Write(HtmlRenderer renderer, YamlFrontMatterBlock obj) | ||
{ | ||
if (InclusionContext.IsInclude) | ||
{ | ||
return; | ||
} | ||
|
||
var content = obj.Lines.ToString(); | ||
try | ||
{ | ||
using StringReader reader = new StringReader(content); | ||
var result = YamlUtility.Deserialize<Dictionary<string, object>>(reader); | ||
if (result != null) | ||
{ | ||
renderer.Write("<yamlheader").Write($" start=\"{obj.Line + 1}\" end=\"{obj.Line + obj.Lines.Count + 2}\""); | ||
renderer.WriteAttributes(obj).Write(">"); | ||
renderer.Write(WebUtility.HtmlEncode(obj.Lines.ToString())); | ||
renderer.Write("</yamlheader>"); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
// not a valid ymlheader, do nothing | ||
_context.LogWarning("invalid-yaml-header", ex.Message, obj); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
var content = obj.Lines.ToString(); | ||
try | ||
{ | ||
using StringReader reader = new StringReader(content); | ||
var result = YamlUtility.Deserialize<Dictionary<string, object>>(reader); | ||
if (result != null) | ||
{ | ||
renderer.Write("<yamlheader").Write($" start=\"{obj.Line + 1}\" end=\"{obj.Line + obj.Lines.Count + 2}\""); | ||
renderer.WriteAttributes(obj).Write(">"); | ||
renderer.Write(WebUtility.HtmlEncode(obj.Lines.ToString())); | ||
renderer.Write("</yamlheader>"); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
// not a valid ymlheader, do nothing | ||
_context.LogWarning("invalid-yaml-header", ex.Message, obj); | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.