Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HTML Data to SharpClipboard #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions SharpClipboard/Data/HTMLData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace WK.Libraries.SharpClipboardNS.Data
{
public class HtmlData
{
public string URL { get; set; }
public string SelectionText { get; set; }
public string SelectionHTML { get; set; }
public string FullHTML { get; set; }
}
}
7 changes: 6 additions & 1 deletion SharpClipboard/SharpClipboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ public enum ContentTypes
/// <summary>
/// Represents any complex objects.
/// </summary>
Other = 3
Other = 3,

/// <summary>
/// Represents a HTML copied from a browser.
/// </summary>
HTML = 4
}

#endregion
Expand Down
5 changes: 5 additions & 0 deletions SharpClipboard/SharpClipboard.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions SharpClipboard/Views/ClipboardHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
using System.Windows.Forms;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using WK.Libraries.SharpClipboardNS.Data;

namespace WK.Libraries.SharpClipboardNS.Views
{
Expand Down Expand Up @@ -213,6 +215,31 @@ protected override void WndProc(ref Message m)
}
}

// Determines if Copying from a Browser that sends the Extra Info
else if ((SharpClipboardInstance.ObservableFormats.Texts == true)
&& dataObj.GetDataPresent(DataFormats.Html))
{
string html = (string)dataObj.GetData(DataFormats.Html);

var match = Regex.Match(html, "SourceURL:([^\\n]*)");
if (match.Success)
{
string url = match.Groups[1].Value;
var content = html.Substring(match.Index + match.Length);
string stringcontent = (string)dataObj.GetData(DataFormats.StringFormat);
var respObj = new HtmlData()
{
FullHTML = content,
SelectionHTML = content.Substring(content.IndexOf("<!--StartFragment-->") + 20, content.IndexOf("<!--EndFragment-->") - content.IndexOf("<!--StartFragment-->") - 20),
URL = url,
SelectionText = stringcontent
};
SharpClipboardInstance.Invoke(respObj, SharpClipboard.ContentTypes.HTML,
new SourceApplication(GetForegroundWindow(), SharpClipboardInstance.ForegroundWindowHandle(),
GetApplicationName(), GetActiveWindowTitle(), GetApplicationPath()));
}

}
// Determines whether text has been cut/copied.
else if ((SharpClipboardInstance.ObservableFormats.Texts == true) &&
(dataObj.GetDataPresent(DataFormats.Text) || dataObj.GetDataPresent(DataFormats.UnicodeText)))
Expand Down