From 71876febf8e0f582a5c7a43ee1ed41f80a2f646c Mon Sep 17 00:00:00 2001 From: Oleksii Holub <1935960+Tyrrrz@users.noreply.github.com> Date: Sat, 9 Apr 2022 02:52:57 +0300 Subject: [PATCH] Use attachment description as alt text in html Closes #805 --- .../Specs/HtmlWriting/AttachmentSpecs.cs | 2 +- DiscordChatExporter.Core/Discord/Data/Attachment.cs | 4 +++- .../Exporting/Writers/Html/MessageGroupTemplate.cshtml | 6 +++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/DiscordChatExporter.Cli.Tests/Specs/HtmlWriting/AttachmentSpecs.cs b/DiscordChatExporter.Cli.Tests/Specs/HtmlWriting/AttachmentSpecs.cs index c998e773..253ae769 100644 --- a/DiscordChatExporter.Cli.Tests/Specs/HtmlWriting/AttachmentSpecs.cs +++ b/DiscordChatExporter.Cli.Tests/Specs/HtmlWriting/AttachmentSpecs.cs @@ -42,7 +42,7 @@ public record AttachmentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixtur Snowflake.Parse("885654862656843786") ); - var imageUrl = message.QuerySelector("img[alt*=\"attachment\" i]")?.GetAttribute("src"); + var imageUrl = message.QuerySelector(".chatlog__attachment img")?.GetAttribute("src"); // Assert message.Text().Should().Contain("Image attachment"); diff --git a/DiscordChatExporter.Core/Discord/Data/Attachment.cs b/DiscordChatExporter.Core/Discord/Data/Attachment.cs index 67766700..4020cc14 100644 --- a/DiscordChatExporter.Core/Discord/Data/Attachment.cs +++ b/DiscordChatExporter.Core/Discord/Data/Attachment.cs @@ -13,6 +13,7 @@ public partial record Attachment( Snowflake Id, string Url, string FileName, + string? Description, int? Width, int? Height, FileSize FileSize) : IHasId @@ -37,8 +38,9 @@ public partial record Attachment var width = json.GetPropertyOrNull("width")?.GetInt32OrNull(); var height = json.GetPropertyOrNull("height")?.GetInt32OrNull(); var fileName = json.GetProperty("filename").GetNonNullString(); + var description = json.GetPropertyOrNull("description")?.GetNonWhiteSpaceStringOrNull(); var fileSize = json.GetProperty("size").GetInt64().Pipe(FileSize.FromBytes); - return new Attachment(id, url, fileName, width, height, fileSize); + return new Attachment(id, url, fileName, description, width, height, fileSize); } } \ No newline at end of file diff --git a/DiscordChatExporter.Core/Exporting/Writers/Html/MessageGroupTemplate.cshtml b/DiscordChatExporter.Core/Exporting/Writers/Html/MessageGroupTemplate.cshtml index 068ef974..ddd96470 100644 --- a/DiscordChatExporter.Core/Exporting/Writers/Html/MessageGroupTemplate.cshtml +++ b/DiscordChatExporter.Core/Exporting/Writers/Html/MessageGroupTemplate.cshtml @@ -158,19 +158,19 @@ @if (attachment.IsImage) { - Image attachment + @(attachment.Description ?? } else if (attachment.IsVideo) { } else if (attachment.IsAudio) { } else