ClipboardHelper

TheArtOfDev.HtmlRenderer.WPF.Utilities

Helper to encode and set HTML fragment to clipboard. See http://theartofdev.com/2012/11/11/setting-html-and-plain-text-formatting-to-clipboard/..

Methods

CopyToClipboard(string, string)

Clears clipboard and sets the given HTML and plain text fragment to the clipboard, providing additional meta-information for HTML. See String) for HTML fragment details.

html
a html fragment
plainText
the plain text
CopyToClipboard(string)

Clears clipboard and sets the given plain text fragment to the clipboard.

plainText
the plain text
CreateDataObject(string, string) : DataObject

Create DataObject with given html and plain-text ready to be used for clipboard or drag and drop. Handle missing <html> tags, specified start\end segments and Unicode characters.

html
a html fragment
plainText
the plain text
GetByteCount(StringBuilder, int, int) : int

Calculates the number of bytes produced by encoding the string in the string builder in UTF-8 and not .NET default string encoding.

sb
the string builder to count its string
start
optional: the start index to calculate from (default - start of string)
end
optional: the end index to calculate to (default - end of string)

Returns: the number of bytes required to encode the string in UTF-8

GetHtmlDataString(string) : string

Generate HTML fragment data string with header that is required for the clipboard.

html
the html to generate for

Returns: the resulted string

Fields

EndFragment : string

html comment to point the end of html fragment

Header : string

The string contains index references to other spots in the string, so we need placeholders so we can compute the offsets. The <<<<<<<_ strings are just placeholders. We'll back-patch them actual values afterwards. The string layout (<<<) also ensures that it can't appear in the body of the html because the < character must be escaped.

StartFragment : string

html comment to point the beginning of html fragment

_byteCount : char[]

Used to calculate characters byte count in UTF-8