Willy-Kimura / SharpClipboard

A library for anonymously monitoring clipboard entries.
183 stars 34 forks source link

Add HTML Data to SharpClipboard #33

Open Biztactix-Ryan opened 1 year ago

Biztactix-Ryan commented 1 year ago

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.

Willy-Kimura commented 10 months ago

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!

Biztactix-Ryan commented 10 months ago

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

Willy-Kimura commented 10 months ago

Great!