mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-29 05:55:21 -04:00
Use nullable
This commit is contained in:
parent
1bf9d9e2e2
commit
e5a2852165
42 changed files with 195 additions and 196 deletions
|
@ -96,7 +96,7 @@ namespace DiscordChatExporter.Core.Rendering
|
|||
await RenderFieldAsync(writer, FormatDate(message.Timestamp));
|
||||
|
||||
// Content
|
||||
await RenderFieldAsync(writer, FormatMarkdown(message.Content));
|
||||
await RenderFieldAsync(writer, FormatMarkdown(message.Content ?? ""));
|
||||
|
||||
// Attachments
|
||||
var formattedAttachments = message.Attachments.Select(a => a.Url).JoinToString(",");
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -97,7 +97,7 @@ namespace DiscordChatExporter.Core.Rendering
|
|||
if (node is MultiLineCodeBlockNode multilineCodeBlockNode)
|
||||
{
|
||||
// Set CSS class for syntax highlighting
|
||||
var highlightCssClass = !multilineCodeBlockNode.Language.IsNullOrWhiteSpace()
|
||||
var highlightCssClass = !string.IsNullOrWhiteSpace(multilineCodeBlockNode.Language)
|
||||
? $"language-{multilineCodeBlockNode.Language}"
|
||||
: "nohighlight";
|
||||
|
||||
|
@ -153,7 +153,7 @@ namespace DiscordChatExporter.Core.Rendering
|
|||
// Extract message ID if the link points to a Discord message
|
||||
var linkedMessageId = Regex.Match(linkNode.Url, "^https?://discordapp.com/channels/.*?/(\\d+)/?$").Groups[1].Value;
|
||||
|
||||
return linkedMessageId.IsNullOrWhiteSpace()
|
||||
return string.IsNullOrWhiteSpace(linkedMessageId)
|
||||
? $"<a href=\"{Uri.EscapeUriString(linkNode.Url)}\">{HtmlEncode(linkNode.Title)}</a>"
|
||||
: $"<a href=\"{Uri.EscapeUriString(linkNode.Url)}\" onclick=\"scrollToMessage(event, '{linkedMessageId}')\">{HtmlEncode(linkNode.Title)}</a>";
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ namespace DiscordChatExporter.Core.Rendering
|
|||
private string FormatMarkdown(IReadOnlyList<Node> nodes, bool isTopLevel)
|
||||
{
|
||||
// Emojis are jumbo if all top-level nodes are emoji nodes or whitespace text nodes
|
||||
var isJumbo = isTopLevel && nodes.All(n => n is EmojiNode || n is TextNode textNode && textNode.Text.IsNullOrWhiteSpace());
|
||||
var isJumbo = isTopLevel && nodes.All(n => n is EmojiNode || n is TextNode textNode && string.IsNullOrWhiteSpace(textNode.Text));
|
||||
|
||||
return nodes.Select(n => FormatMarkdown(n, isJumbo)).JoinToString("");
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace DiscordChatExporter.Core.Rendering
|
|||
return $"before {FormatDate(before.Value)}";
|
||||
|
||||
// Neither
|
||||
return null;
|
||||
return "";
|
||||
}
|
||||
|
||||
private string FormatMarkdown(Node node)
|
||||
|
@ -131,43 +131,43 @@ namespace DiscordChatExporter.Core.Rendering
|
|||
await writer.WriteLineAsync("{Embed}");
|
||||
|
||||
// Author name
|
||||
if (!(embed.Author?.Name).IsNullOrWhiteSpace())
|
||||
if (!string.IsNullOrWhiteSpace(embed.Author?.Name))
|
||||
await writer.WriteLineAsync(embed.Author?.Name);
|
||||
|
||||
// URL
|
||||
if (!embed.Url.IsNullOrWhiteSpace())
|
||||
if (!string.IsNullOrWhiteSpace(embed.Url))
|
||||
await writer.WriteLineAsync(embed.Url);
|
||||
|
||||
// Title
|
||||
if (!embed.Title.IsNullOrWhiteSpace())
|
||||
if (!string.IsNullOrWhiteSpace(embed.Title))
|
||||
await writer.WriteLineAsync(FormatMarkdown(embed.Title));
|
||||
|
||||
// Description
|
||||
if (!embed.Description.IsNullOrWhiteSpace())
|
||||
if (!string.IsNullOrWhiteSpace(embed.Description))
|
||||
await writer.WriteLineAsync(FormatMarkdown(embed.Description));
|
||||
|
||||
// Fields
|
||||
foreach (var field in embed.Fields)
|
||||
{
|
||||
// Name
|
||||
if (!field.Name.IsNullOrWhiteSpace())
|
||||
if (!string.IsNullOrWhiteSpace(field.Name))
|
||||
await writer.WriteLineAsync(field.Name);
|
||||
|
||||
// Value
|
||||
if (!field.Value.IsNullOrWhiteSpace())
|
||||
if (!string.IsNullOrWhiteSpace(field.Value))
|
||||
await writer.WriteLineAsync(field.Value);
|
||||
}
|
||||
|
||||
// Thumbnail URL
|
||||
if (!(embed.Thumbnail?.Url).IsNullOrWhiteSpace())
|
||||
if (!string.IsNullOrWhiteSpace(embed.Thumbnail?.Url))
|
||||
await writer.WriteLineAsync(embed.Thumbnail?.Url);
|
||||
|
||||
// Image URL
|
||||
if (!(embed.Image?.Url).IsNullOrWhiteSpace())
|
||||
if (!string.IsNullOrWhiteSpace(embed.Image?.Url))
|
||||
await writer.WriteLineAsync(embed.Image?.Url);
|
||||
|
||||
// Footer text
|
||||
if (!(embed.Footer?.Text).IsNullOrWhiteSpace())
|
||||
if (!string.IsNullOrWhiteSpace(embed.Footer?.Text))
|
||||
await writer.WriteLineAsync(embed.Footer?.Text);
|
||||
|
||||
await writer.WriteLineAsync();
|
||||
|
@ -201,7 +201,8 @@ namespace DiscordChatExporter.Core.Rendering
|
|||
await RenderMessageHeaderAsync(writer, message);
|
||||
|
||||
// Content
|
||||
await writer.WriteLineAsync(FormatMarkdown(message.Content));
|
||||
if (!string.IsNullOrWhiteSpace(message.Content))
|
||||
await writer.WriteLineAsync(FormatMarkdown(message.Content));
|
||||
|
||||
// Separator
|
||||
await writer.WriteLineAsync();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue