Skip to content

Commit

Permalink
macOS: extract html
Browse files Browse the repository at this point in the history
  • Loading branch information
Gae24 committed Oct 17, 2024
1 parent f9b466b commit 63f038e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/platform/osx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ impl<'clipboard> Get<'clipboard> {
}

pub(crate) fn html(self) -> Result<String, Error> {
unsafe { self.clipboard.string_from_type(NSPasteboardTypeHTML) }
let html = unsafe { self.clipboard.string_from_type(NSPasteboardTypeHTML) }?;
extract_html(html)
}

#[cfg(feature = "image-data")]
Expand Down Expand Up @@ -352,6 +353,18 @@ fn add_clipboard_exclusions(clipboard: &mut Clipboard, exclude_from_history: boo
}
}

fn extract_html(html: String) -> Result<String> {
let start_tag = "<body>";
let end_tag = "</body>";

// Locate the start index of the <body> tag
let start_index = html.find(start_tag)? + start_tag.len();
// Locate the end index of the </body> tag
let end_index = html.find(end_tag)?;

Ok(html[start_index..end_index].to_string())
}

/// Apple-specific extensions to the [`Set`](crate::Set) builder.
pub trait SetExtApple: private::Sealed {
/// Excludes the data which will be set on the clipboard from being added to
Expand Down

0 comments on commit 63f038e

Please sign in to comment.