SharpClipboard
SharpClipboard copied to clipboard
Add HTML Data to SharpClipboard
Sorry, I haven't written the tests for it... But this essentially allows you to get the URL as well as the copied text and HTML from browsers, which is rather useful.
I have tested it in Chrome 114.0.5735.199, Firefox 115.0.1 and Edge 114.0.1823.67 Works the same on all of them.
Great feature! Html format detection can be a great value-add for a number of use cases.
However I'm seeing a breaking change from the current setup where both plain and html copied texts are both categorized as ContentTypes.Text
. Probably to sweeten how it would typically work we can have a ContentFormats
enumeration that would allow one to drill-down to the precise format of the content copied, e.g in this case ContentFormats.Html
or if plain text ContentFormats.PlainText
. The resulting feature would then look something similar to this:
if (e.ContentType == SharpClipboard.ContentTypes.Text)
{
// You can simply get the content in plain text format...
Debug.WriteLine(clipboard.ClipboardText); // or e.Content.ToString()
// or better yet get the Html format...
if (e.ContentFormat == ContentFormats.Html)
{
// Cast copied content to HtmlData.
var html = (HtmlData)e.Content;
Debug.WriteLine(html.SelectedHtml);
}
}
Let me know how we can improve on this. Many thanks!
However you want to do it... Your nuget... I just needed quick and dirty Web citation for what my use case was... If you can see a better way to do it... All yours
Great!