diff --git a/imessage-exporter/src/exporters/html.rs b/imessage-exporter/src/exporters/html.rs index bce763ba..c37d0005 100644 --- a/imessage-exporter/src/exporters/html.rs +++ b/imessage-exporter/src/exporters/html.rs @@ -1029,6 +1029,17 @@ impl<'a> BalloonFormatter<&'a Message> for HTML<'a> { out_s.push_str("\" "); } + // Add lyrics, if any + if let Some(lyrics) = &balloon.lyrics { + out_s.push_str("
"); + for line in lyrics { + out_s.push_str("

"); + out_s.push_str(line); + out_s.push_str("

"); + } + out_s.push_str("
"); + } + // Header end out_s.push_str(""); @@ -2461,6 +2472,7 @@ mod balloon_format_tests { artist: Some("artist"), album: Some("album"), track_name: Some("track_name"), + lyrics: None, }; let expected = exporter.format_music(&balloon, &Config::fake_message()); @@ -2469,6 +2481,28 @@ mod balloon_format_tests { assert_eq!(expected, actual); } + #[test] + fn can_format_html_music_lyrics() { + // Create exporter + let options = Options::fake_options(crate::app::export_type::ExportType::Html); + let config = Config::fake_app(options); + let exporter = HTML::new(&config).unwrap(); + + let balloon = MusicMessage { + url: Some("url"), + preview: None, + artist: Some("artist"), + album: Some("album"), + track_name: Some("track_name"), + lyrics: Some(vec!["a", "b"]), + }; + + let expected = exporter.format_music(&balloon, &Config::fake_message()); + let actual = "
track_name

a

b

artist
album
"; + + assert_eq!(expected, actual); + } + #[test] fn can_format_html_collaboration() { // Create exporter diff --git a/imessage-exporter/src/exporters/txt.rs b/imessage-exporter/src/exporters/txt.rs index db018c04..66a492cc 100644 --- a/imessage-exporter/src/exporters/txt.rs +++ b/imessage-exporter/src/exporters/txt.rs @@ -735,6 +735,14 @@ impl<'a> BalloonFormatter<&'a str> for TXT<'a> { fn format_music(&self, balloon: &MusicMessage, indent: &str) -> String { let mut out_s = String::new(); + if let Some(lyrics) = &balloon.lyrics { + self.add_line(&mut out_s, "Lyrics:", indent); + for line in lyrics { + self.add_line(&mut out_s, line, indent); + } + self.add_line(&mut out_s, "\n", indent); + } + if let Some(track_name) = balloon.track_name { self.add_line(&mut out_s, track_name, indent); } @@ -1869,6 +1877,7 @@ mod balloon_format_tests { artist: Some("artist"), album: Some("album"), track_name: Some("track_name"), + lyrics: None, }; let expected = exporter.format_music(&balloon, ""); @@ -1877,6 +1886,28 @@ mod balloon_format_tests { assert_eq!(expected, actual); } + #[test] + fn can_format_txt_music_lyrics() { + // Create exporter + let options = Options::fake_options(crate::app::export_type::ExportType::Txt); + let config = Config::fake_app(options); + let exporter = TXT::new(&config).unwrap(); + + let balloon = MusicMessage { + url: Some("url"), + preview: None, + artist: Some("artist"), + album: Some("album"), + track_name: Some("track_name"), + lyrics: Some(vec!["a", "b"]), + }; + + let expected = exporter.format_music(&balloon, ""); + let actual = "Lyrics:\na\nb\n\n\ntrack_name\nalbum\nartist\nurl\n"; + + assert_eq!(expected, actual); + } + #[test] fn can_format_txt_collaboration() { // Create exporter