-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
HTML serialization #3619
HTML serialization #3619
Conversation
Thanks for working on this. Could you please:
|
Selection has been added, but unfortunately broke some existing tests. I'll fix that when I have time. :) |
from what I've read, it looks like an embedder would have to intercept the it looks like you're doing that in the code, but it's not working for me. I'll try a different browser. |
When you click the 'serialize' button, it should add a html code onto your clipboard of the selected part of the terminal. Don't copy the html in the visible window, that's there for debugging or to save as html manually if copy to clipboard doesn't work. From as soon as the button is clicked, you should be able to paste the selected part in an editor that supports pasting html like word or something like that. |
Doesn't work for me in edge, but I see it working for some cases that I've tried in Chrome 👍🏼. |
Copying itself does work reliably for me in Chrome, however when the alternate screen is active, it still copies random content from the primary screen. |
It actually does work in edge for me as well. I was expecting the background color to match that of the terminal, but perhaps that's not necessary. I see that's done here if it's set |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @silamon, looks pretty close 😍
BG/FG colors were correct in the HTML I got, although when I first tested it by pasting into Word, it turned out inverted - that's Word's problem though, the HTML itself is correct and opening it in Chrome gets the colors right. |
Yes @Eugeny I saw the same - it was inverted in apple notes, but not in chrome. |
Co-authored-by: Daniel Imms <2193314+Tyriar@users.noreply.github.com>
I can't seem to reproduce the text being pasted inverted. Do you see colored text in that paste or is it just clear text in black? |
@silamon it's all colored with the exception of black and white being inverted. I don't even think it's your fault - my custom HTML copy implementation suffers from the same if background and foreground are #000 and #fff respectively. |
function listener(e: any) { | ||
e.clipboardData.setData("text/html", output); | ||
e.preventDefault(); | ||
} | ||
document.addEventListener("copy", listener); | ||
document.execCommand("copy"); | ||
document.removeEventListener("copy", listener); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've used the new asynchronous clipboard api, but a lot of browsers don't support it. I've replaced that with a deprecated alternative, which seems to be more supported anyway.
It would be better if we moved on to more modern APIs like navigator.clipboard
, it looks like just IE doesn't support writing to the clipboard which doesn't matter https://caniuse.com/async-clipboard
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested with navigator.clipboard in the first commit and Firefox doesn't support it. The caniuse link does mention that as well.
addons/xterm-addon-serialize/typings/xterm-addon-serialize.d.ts
Outdated
Show resolved
Hide resolved
addons/xterm-addon-serialize/typings/xterm-addon-serialize.d.ts
Outdated
Show resolved
Hide resolved
addons/xterm-addon-serialize/typings/xterm-addon-serialize.d.ts
Outdated
Show resolved
Hide resolved
addons/xterm-addon-serialize/typings/xterm-addon-serialize.d.ts
Outdated
Show resolved
Hide resolved
* | ||
* @param options Custom options to allow control over what gets serialized. | ||
*/ | ||
public serializeAsHTML(options?: Partial<IHTMLSerializeOptions>): string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add some basic test to SerializeAddon.api.ts
that cover:
- Each option
- Colored/styled vs all default color/style text
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll write some unit tests as soon as I have time. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests have been added. Unfortunately, not as playwright tests since I couldn't get it to work at this moment.
Looks good other than those comments 👍 |
The tests look good 👍🏼 thanks |
Fixes #1883
Makes use of the existing serialize addon and the templates