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

Implement getting HTML on X11 #130

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

lucieleblanc
Copy link

No description provided.

@lucieleblanc lucieleblanc changed the title Implement getting HTML from clipboard Implement getting HTML on X11 Jan 20, 2024
Copy link
Collaborator

@complexspaces complexspaces left a 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! I didn't look at this originally because it was still a draft but I had a spare moment and thought it may be helpful to guide this one in.

Comment on lines +160 to +162
pub fn from_alt_text(alt_text: String) -> Self {
Self { alt_text, ..Default::default() }
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a valid function to expose? If the user doesn't have any HTML in the first place it seems like they'd be better off using set_text() instead.

@@ -146,6 +146,22 @@ impl<'a> ImageData<'a> {
}
}

#[derive(Debug, Default)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Let's remove the Default implementation here. It makes it harder to maintain version compatibility in the future.

Comment on lines +82 to +85
/// Fetches HTML from the clipboard and returns it.
pub fn get_html(&mut self) -> Result<HTMLData, Error> {
self.get().html()
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Do you think HTML is a common enough case to add this to the main Clipboard structure? I would prefer to expose this only through the Get builder to keep it tidy.


let html_result = self.inner.read(&html_format, selection);
if let Ok(html_data) = html_result {
let html: String = html_data.bytes.into_iter().map(|c| c as char).collect();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct? My understanding that HTML can contain UTF-8 so we should just use String::from_utf8 here.

Comment on lines +892 to +899
let alt_text_formats = [
self.inner.atoms.UTF8_STRING,
self.inner.atoms.UTF8_MIME_0,
self.inner.atoms.UTF8_MIME_1,
self.inner.atoms.STRING,
self.inner.atoms.TEXT,
self.inner.atoms.TEXT_MIME_UNKNOWN,
];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we find a way to extract this into a reusable construct that get_text can use as well?

Comment on lines +910 to +918
if let Ok(alt_text_data) = alt_text_result {
data.alt_text = if alt_text_data.format == self.inner.atoms.STRING {
// ISO Latin-1
// See: https://stackoverflow.com/questions/28169745/what-are-the-options-to-convert-iso-8859-1-latin-1-to-a-string-utf-8
alt_text_data.bytes.into_iter().map(|c| c as char).collect::<String>()
} else {
String::from_utf8(alt_text_data.bytes).map_err(|_| Error::ConversionFailure)?
};
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, because the logic is also duplicated from get_text.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants