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
Feature request: copy as HTML #811
Comments
Mintty supports Export as HTML already (HTML Screen Dump from extended context menu), it's copied to a file, however. |
Either of the built-in Windows 10 apps I mentioned (Mail, OneNote) would be good candidates. I just did some tests with the debugger to try to dig into how this works. mintty calls user32!SetClipboardData with three formats: 0xd (Unicode text), 1 (plain text), and 0xc09f (RTF). Word retrieves the RTF format data on paste from mintty. When I copy from Word, it calls SetClipboardData for a whole plethora of formats:
However, in the target apps, I don't see any hits on GetClipboardData -- it seems the clipboard API in UWP is entirely different. So I can't confirm they are using HTML, but it seems the most likely explanation. |
Where do you have this definition from? I see no defined value for CF_HTML in the docs or in the Windows SDK (WinUser.h does not mention CF_HTML at all). Also given that the description of the HTML Clipboard Format is utterly obscure and examples are broken, I don't see a promising way to implement this. |
That's just the string returned by GetClipboardFormatNameA(0xc0bb), which I called inside the debugger, to figure out what formats Word was emitting. I don't know if that value is global or unique to my system -- from a quick read of the docs it looks like you are supposed to call something like RegisterClipboardFormat("HTML Format"), and it returns the ID. Here's an example that came up in a quick search: |
Another old example: https://blogs.msdn.microsoft.com/jmstall/2007/01/21/copying-html-on-the-clipboard/ It looks like the format is quite complex, but if we're lucky just pasting a prepared header on the front of standard HTML may be good enough. |
What I wrote above about pasting a prepared header is bogus -- there are byte offsets in the header, but if you don't have context it's not terribly complex. In any case, this is the best summary of the format, sample code, and pointers to other references on the topic that I found: https://theartofdev.com/2014/06/12/setting-htmltext-to-clipboard-revisited/ |
I had seen the latter page already but its examples are broken, too. In Figure 2, the offset values don't make any sense. |
Anyway, from these hints I guess I can construct something. A browser apparently copies this format, too, so it can be read to check the format. For the desired direction however, copying to the clipboard, I need an application that can paste it, as requested, for testing. Not something speculative but something I can use, please. |
I think the problem with that example is that something has appended extra trailing whitepace in the version on the website. If I trim the trailing whitespace, at least the "StartHTML" field makes sense:
I believe the EndHTML is also correct if you account for mangling of the UTF8. Do you have access to Windows 10? As I said, the Mail and OneNote apps that come with it both paste this format. I'm checking whether there's a good (non-UWP) app that you can use. |
Yes, but StartFragment and StartSelection make no sense at all. Also there is no clear explanation about these two things which are the same in all examples. |
Here's an open source Win32 app that supports HTML paste: http://openlivewriter.org/ https://github.com/OpenLiveWriter/OpenLiveWriter/blob/master/src/managed/OpenLiveWriter.CoreServices/DataObject/HTMLDataObject.cs seems to be the main parser. The downside is that you need to create a throwaway account on a blog site (if you don't already have one) to use it. |
Curiously they emit using header version 1.0 that Raymond Chen's blog explicitly says is broken :) |
Test case: copy some HTML from a browser (Firefox): |
Released 2.9.4; note that HTML does not include Sixel graphics (yet). |
Thanks! Sorry I missed this when you first made the commit. I've tested and have some compat-related improvements to the HTML output. I'll clean them up and send you a PR to review. |
Released 2.9.5. HTML copy not enabled by default, but added to Options menu. |
I finally got around to doing this, but it turns out the fixes you already made for "tools like PowerPoint" in c2f48e0 also subsume my changes. Thanks again! |
mintty supports copying the selection as rich text format, however I've noticed that some "modern" Windows apps don't seem to support rich text and fall back to pasting plain text -- this includes the Mail app, and the OneNote app, for example. A workaround I've found for this is to copy from mintty, paste into Word, which imports/renders the rich text, then paste into the target application. I'm guessing (but haven't verified) that Word is converting to HTML here; if so, it would be nice if mintty natively supported copying the HTML.
The text was updated successfully, but these errors were encountered: