Skip to content

Commit 1553783

Browse files
author
ArthurHub
committed
make html fragment just like IE creates it
1 parent 87de60c commit 1553783

File tree

2 files changed

+19
-28
lines changed

2 files changed

+19
-28
lines changed

Source/HtmlRenderer/Utils/ClipboardHelper.cs

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ internal static class ClipboardHelper
2424
/// The string layout (<![CDATA[<<<]]>) also ensures that it can't appear in the body of the html because the <![CDATA[<]]> <br/>
2525
/// character must be escaped. <br/>
2626
/// </summary>
27-
private const string Header = @"Format:HTML Format
28-
Version:1.0
29-
StartHTML:<<<<<<<1
30-
EndHTML:<<<<<<<2
31-
StartFragment:<<<<<<<3
32-
EndFragment:<<<<<<<4
33-
StartSelection:<<<<<<<3
34-
EndSelection:<<<<<<<3";
27+
private const string Header = @"Version:1.0
28+
StartHTML:<<<<<<<<1
29+
EndHTML:<<<<<<<<2
30+
StartFragment:<<<<<<<<3
31+
EndFragment:<<<<<<<<4
32+
StartSelection:<<<<<<<<3
33+
EndSelection:<<<<<<<<3
34+
SourceURL:about:blank";
3535

3636
/// <summary>
3737
/// html comment to point the beginning of html fragment
@@ -60,18 +60,15 @@ internal static class ClipboardHelper
6060
/// In all cases creating a proper CF_HTML header:<br/>
6161
/// <code>
6262
/// <![CDATA[
63-
/// Format:HTML Format
6463
/// Version:1.0
65-
/// StartHTML: 177
66-
/// EndHTML: 329
67-
/// StartFragment: 277
68-
/// EndFragment: 295
69-
/// StartSelection: 277
70-
/// EndSelection: 277
64+
/// StartHTML:000000177
65+
/// EndHTML:000000329
66+
/// StartFragment:000000277
67+
/// EndFragment:000000295
68+
/// StartSelection:000000277
69+
/// EndSelection:000000277
7170
/// <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
72-
/// <html><body>
73-
/// <!--StartFragment-->hello <b>world</b><!--EndFragment-->
74-
/// </body></html>
71+
/// <html><body><!--StartFragment-->hello <b>world</b><!--EndFragment--></body></html>
7572
/// ]]>
7673
/// </code>
7774
/// See format specification here: http://msdn.microsoft.com/library/default.asp?url=/workshop/networking/clipboard/htmlclipboard.asp
@@ -128,13 +125,11 @@ private static string GetHtmlDataString(string html)
128125
{
129126
// the given html doesn't contain html or body tags so we need to add them and place start/end fragments around the given html only
130127
sb.Append("<html><body>");
131-
sb.AppendLine();
132128
sb.Append(StartFragment);
133129
fragmentStart = sb.Length;
134130
sb.Append(html);
135131
fragmentEnd = sb.Length;
136132
sb.Append(EndFragment);
137-
sb.AppendLine();
138133
sb.Append("</body></html>");
139134
}
140135
else
@@ -152,7 +147,6 @@ private static string GetHtmlDataString(string html)
152147
if (bodyOpenEndIdx > -1)
153148
sb.Append(html, htmlOpenEndIdx > -1 ? htmlOpenEndIdx : 0, bodyOpenEndIdx - (htmlOpenEndIdx > -1 ? htmlOpenEndIdx : 0));
154149

155-
sb.AppendLine();
156150
sb.Append(StartFragment);
157151
fragmentStart = sb.Length;
158152

@@ -162,7 +156,6 @@ private static string GetHtmlDataString(string html)
162156

163157
fragmentEnd = sb.Length;
164158
sb.Append(EndFragment);
165-
sb.AppendLine();
166159

167160
if (innerHtmlEnd < html.Length)
168161
sb.Append(html, innerHtmlEnd, html.Length - innerHtmlEnd);
@@ -179,10 +172,10 @@ private static string GetHtmlDataString(string html)
179172
}
180173

181174
// Back-patch offsets (scan only the header part for performance)
182-
sb.Replace("<<<<<<<4", String.Format("{0,8}", fragmentEnd), 0, Header.Length);
183-
sb.Replace("<<<<<<<3", String.Format("{0,8}", fragmentStart), 0, Header.Length);
184-
sb.Replace("<<<<<<<2", String.Format("{0,8}", sb.Length), 0, Header.Length);
185-
sb.Replace("<<<<<<<1", String.Format("{0,8}", Header.Length), 0, Header.Length);
175+
sb.Replace("<<<<<<<<4", fragmentEnd.ToString("D9"), 0, Header.Length);
176+
sb.Replace("<<<<<<<<3", fragmentStart.ToString("D9"), 0, Header.Length);
177+
sb.Replace("<<<<<<<<2", sb.Length.ToString("D9"), 0, Header.Length);
178+
sb.Replace("<<<<<<<<1", Header.Length.ToString("D9"), 0, Header.Length);
186179

187180
return sb.ToString();
188181
}

Source/HtmlRenderer/Utils/DomUtils.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,6 @@ private static void WriteHtml(StringBuilder sb, CssBox box, HtmlGenerationStyle
638638
if (box.HtmlTag != null && !box.HtmlTag.IsSingle)
639639
{
640640
sb.AppendFormat("</{0}>", box.HtmlTag.Name);
641-
if (!box.IsInline && !box.IsBrElement)
642-
sb.AppendLine();
643641
}
644642
}
645643
}

0 commit comments

Comments
 (0)