cleanup RoundtripRenderer

This commit is contained in:
Ruud Poutsma
2020-10-25 15:48:19 +01:00
parent 0e8c312fda
commit c8da430134
4 changed files with 5 additions and 69 deletions

View File

@@ -38,8 +38,8 @@ In order:
- ~~check char.IsNewline() calls~~
- ~~introduce feature flag~~
- ~~extract MarkdownRenderer~~
- cleanup NormalizeRenderer (MarkdownRenderer)
- deduplicate MarkdownRenderer and NormalizeRenderer code
- ~~cleanup NormalizeRenderer (MarkdownRenderer)~~
- ~~deduplicate MarkdownRenderer and NormalizeRenderer code~~
- do pull request feedback
- split HeadingBlock into AtxHeadingBlock and SetextHeadingBlock?
- fix broken pre-existing tests

View File

@@ -3,6 +3,7 @@
// See the license.txt file in the project root for more information.
using Markdig.Syntax;
using System;
namespace Markdig.Renderers.Normalize
{
@@ -18,7 +19,8 @@ namespace Markdig.Renderers.Normalize
{
if (obj is FencedCodeBlock fencedCodeBlock)
{
var opening = new string(fencedCodeBlock.FencedChar, fencedCodeBlock.FencedCharCount);
var fencedCharCount = Math.Min(fencedCodeBlock.OpeningFencedCharCount, fencedCodeBlock.ClosingFencedCharCount);
var opening = new string(fencedCodeBlock.FencedChar, fencedCharCount);
renderer.Write(opening);
if (fencedCodeBlock.Info != null)
{

View File

@@ -17,8 +17,6 @@ namespace Markdig.Renderers.Roundtrip
protected override void Write(RoundtripRenderer renderer, ListBlock listBlock)
{
renderer.RenderLinesBefore(listBlock);
var compact = renderer.CompactParagraph;
renderer.CompactParagraph = !listBlock.IsLoose;
if (listBlock.IsOrdered)
{
int index = 0;
@@ -89,8 +87,6 @@ namespace Markdig.Renderers.Roundtrip
renderer.RenderLinesAfter(listItem);
}
}
renderer.CompactParagraph = compact;
renderer.RenderLinesAfter(listBlock);
}

View File

@@ -44,68 +44,6 @@ namespace Markdig.Renderers.Roundtrip
ObjectRenderers.Add(new LiteralInlineRenderer());
}
public bool CompactParagraph { get; set; }
///// <summary>
///// Writes the attached <see cref="HtmlAttributes"/> on the specified <see cref="MarkdownObject"/>.
///// </summary>
///// <param name="obj">The object.</param>
///// <returns></returns>
//public NormalizeRenderer WriteAttributes(MarkdownObject obj)
//{
// if (obj == null) throw new ArgumentNullException(nameof(obj));
// return WriteAttributes(obj.TryGetAttributes());
//}
///// <summary>
///// Writes the specified <see cref="HtmlAttributes"/>.
///// </summary>
///// <param name="attributes">The attributes to render.</param>
///// <returns>This instance</returns>
//public NormalizeRenderer WriteAttributes(HtmlAttributes attributes)
//{
// if (attributes == null)
// {
// return this;
// }
// if (attributes.Id != null)
// {
// Write(" id=\"").WriteEscape(attributes.Id).Write("\"");
// }
// if (attributes.Classes != null && attributes.Classes.Count > 0)
// {
// Write(" class=\"");
// for (int i = 0; i < attributes.Classes.Count; i++)
// {
// var cssClass = attributes.Classes[i];
// if (i > 0)
// {
// Write(" ");
// }
// WriteEscape(cssClass);
// }
// Write("\"");
// }
// if (attributes.Properties != null && attributes.Properties.Count > 0)
// {
// foreach (var property in attributes.Properties)
// {
// Write(" ").Write(property.Key);
// if (property.Value != null)
// {
// Write("=").Write("\"");
// WriteEscape(property.Value);
// Write("\"");
// }
// }
// }
// return this;
//}
/// <summary>
/// Writes the lines of a <see cref="LeafBlock"/>
/// </summary>