Skip to content

Commit 87de60c

Browse files
author
ArthurHub
committed
remove generated html indent support
1 parent 5114cb4 commit 87de60c

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

Source/HtmlRenderer/Utils/ClipboardHelper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ internal static class ClipboardHelper
8181
public static DataObject CreateDataObject(string html, string plainText)
8282
{
8383
var dataObject = new DataObject();
84-
dataObject.SetData(DataFormats.Html, !string.IsNullOrEmpty(html) ? GetHtmlDataString(html) : html);
84+
var htmlFragment = !string.IsNullOrEmpty(html) ? GetHtmlDataString(html) : html;
85+
dataObject.SetData(DataFormats.Html, htmlFragment);
8586
dataObject.SetData(DataFormats.Text, plainText);
8687
return dataObject;
8788
}

Source/HtmlRenderer/Utils/DomUtils.cs

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ public static string GenerateHtml(CssBox root, HtmlGenerationStyle styleGen = Ht
437437
var sb = new StringBuilder();
438438
if (root != null)
439439
{
440-
WriteHtml(sb, root, 0, styleGen, onlySelected ? CollectSelectedHtmlTags(root) : null);
440+
WriteHtml(sb, root, styleGen, onlySelected ? CollectSelectedHtmlTags(root) : null);
441441
}
442442
return sb.ToString();
443443
}
@@ -596,10 +596,9 @@ private static bool CollectSelectedHtmlTags(CssBox box, Dictionary<HtmlTag, bool
596596
/// </summary>
597597
/// <param name="sb">the string builder to write html into</param>
598598
/// <param name="box">the html sub-tree to write</param>
599-
/// <param name="indent">the indent to use for nice formatting</param>
600599
/// <param name="styleGen">Controls the way styles are generated when html is generated</param>
601600
/// <param name="selectedTags">Control if to generate only selected tags, if given only tags found in collection will be generated</param>
602-
private static void WriteHtml(StringBuilder sb, CssBox box, int indent, HtmlGenerationStyle styleGen, Dictionary<HtmlTag, bool> selectedTags)
601+
private static void WriteHtml(StringBuilder sb, CssBox box, HtmlGenerationStyle styleGen, Dictionary<HtmlTag, bool> selectedTags)
603602
{
604603
if (box.HtmlTag == null || selectedTags == null || selectedTags.ContainsKey(box.HtmlTag))
605604
{
@@ -608,16 +607,13 @@ private static void WriteHtml(StringBuilder sb, CssBox box, int indent, HtmlGene
608607
if (box.HtmlTag.Name != "link" || !box.HtmlTag.Attributes.ContainsKey("href") ||
609608
(!box.HtmlTag.Attributes["href"].StartsWith("property") && !box.HtmlTag.Attributes["href"].StartsWith("method")))
610609
{
611-
WriteHtmlTag(sb, box, indent, styleGen);
612-
indent = indent + (box.HtmlTag.IsSingle ? 0 : 1);
610+
WriteHtmlTag(sb, box, styleGen);
613611
}
614612

615613
if (styleGen == HtmlGenerationStyle.InHeader && box.HtmlTag.Name == "html" && box.HtmlContainer.CssData != null)
616614
{
617-
sb.Append(new string(' ', indent * 2));
618615
sb.AppendLine("<head>");
619-
WriteStylesheet(sb, box.HtmlContainer.CssData, indent + 1);
620-
sb.Append(new string(' ', indent * 2));
616+
WriteStylesheet(sb, box.HtmlContainer.CssData);
621617
sb.AppendLine("</head>");
622618
}
623619
}
@@ -636,7 +632,7 @@ private static void WriteHtml(StringBuilder sb, CssBox box, int indent, HtmlGene
636632

637633
foreach (var childBox in box.Boxes)
638634
{
639-
WriteHtml(sb, childBox, indent, styleGen, selectedTags);
635+
WriteHtml(sb, childBox, styleGen, selectedTags);
640636
}
641637

642638
if (box.HtmlTag != null && !box.HtmlTag.IsSingle)
@@ -653,12 +649,9 @@ private static void WriteHtml(StringBuilder sb, CssBox box, int indent, HtmlGene
653649
/// </summary>
654650
/// <param name="sb">the string builder to write html into</param>
655651
/// <param name="box">the css box with the html tag to write</param>
656-
/// <param name="indent">the indent to use for nice formatting</param>
657652
/// <param name="styleGen">Controls the way styles are generated when html is generated</param>
658-
private static void WriteHtmlTag(StringBuilder sb, CssBox box, int indent, HtmlGenerationStyle styleGen)
653+
private static void WriteHtmlTag(StringBuilder sb, CssBox box, HtmlGenerationStyle styleGen)
659654
{
660-
if (!box.IsInline && !box.IsBrElement)
661-
sb.Append(new string(' ', indent * 2));
662655
sb.AppendFormat("<{0}", box.HtmlTag.Name);
663656

664657
// collect all element style properties including from stylesheet
@@ -722,8 +715,6 @@ private static void WriteHtmlTag(StringBuilder sb, CssBox box, int indent, HtmlG
722715
}
723716

724717
sb.AppendFormat("{0}>", box.HtmlTag.IsSingle ? "/" : "");
725-
if (!box.IsInline && !box.IsBrElement)
726-
sb.AppendLine();
727718
}
728719

729720
/// <summary>
@@ -763,14 +754,11 @@ private static Dictionary<string, string> StripDefaultStyles(CssBox box, Diction
763754
/// </summary>
764755
/// <param name="sb">the string builder to write stylesheet into</param>
765756
/// <param name="cssData">the css data to write to the head</param>
766-
/// <param name="indent">the indent to use for nice formatting</param>
767-
private static void WriteStylesheet(StringBuilder sb, CssData cssData, int indent)
757+
private static void WriteStylesheet(StringBuilder sb, CssData cssData)
768758
{
769-
sb.Append(new string(' ', indent * 2));
770759
sb.AppendLine("<style type=\"text/css\">");
771760
foreach (var cssBlocks in cssData.MediaBlocks["all"])
772761
{
773-
sb.Append(new string(' ', (indent + 1) * 2));
774762
sb.Append(cssBlocks.Key);
775763
sb.Append(" { ");
776764
foreach (var cssBlock in cssBlocks.Value)
@@ -784,7 +772,6 @@ private static void WriteStylesheet(StringBuilder sb, CssData cssData, int inden
784772
sb.Append(" }");
785773
sb.AppendLine();
786774
}
787-
sb.Append(new string(' ', indent * 2));
788775
sb.AppendLine("</style>");
789776
}
790777

0 commit comments

Comments
 (0)