mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-06-14 11:26:33 +00:00
Fix link text extraction in MarkdownToInlinesConverter to handle formatted inline children
- Add GetPlainText helper that recursively collects text from all inline children (LiteralInline for leaf text, ContainerInline recurses into children) - Use GetPlainText(link) instead of .OfType<LiteralInline>() so bold/italic labels like [**text**](url) are rendered correctly - Fix BulletType: ListBlock.BulletType is a char in Markdig, not an enum; remove the incorrect switch expression and use the char directly Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
This commit is contained in:
@@ -20,6 +20,14 @@ public class MarkdownToInlinesConverter : IValueConverter
|
||||
.UseEmphasisExtras()
|
||||
.Build();
|
||||
|
||||
private static string GetPlainText(MarkdownInline inline) =>
|
||||
inline switch
|
||||
{
|
||||
LiteralInline literal => literal.Content.ToString(),
|
||||
ContainerInline container => string.Concat(container.Select(GetPlainText)),
|
||||
_ => string.Empty,
|
||||
};
|
||||
|
||||
private static void ProcessInline(
|
||||
InlineCollection inlines,
|
||||
MarkdownInline markdownInline,
|
||||
@@ -83,13 +91,7 @@ public class MarkdownToInlinesConverter : IValueConverter
|
||||
{
|
||||
inlines.Add(
|
||||
new InlineUIContainer(
|
||||
new HyperLink
|
||||
{
|
||||
Text = string.Concat(
|
||||
link.OfType<LiteralInline>().Select(l => l.Content.ToString())
|
||||
),
|
||||
Url = link.Url,
|
||||
}
|
||||
new HyperLink { Text = GetPlainText(link), Url = link.Url }
|
||||
)
|
||||
);
|
||||
|
||||
@@ -147,15 +149,7 @@ public class MarkdownToInlinesConverter : IValueConverter
|
||||
inlines.Add(new LineBreak());
|
||||
isFirst = false;
|
||||
|
||||
var bulletChar = list.BulletType switch
|
||||
{
|
||||
BulletType.Dash => '-',
|
||||
BulletType.Plus => '+',
|
||||
BulletType.Asterisk => '*',
|
||||
_ => '-'
|
||||
};
|
||||
|
||||
var prefix = list.IsOrdered ? $"{itemOrder++}. " : $"{bulletChar} ";
|
||||
var prefix = list.IsOrdered ? $"{itemOrder++}. " : $"{list.BulletType} ";
|
||||
inlines.Add(new Run(prefix));
|
||||
|
||||
foreach (var subBlock in listItem.OfType<ParagraphBlock>())
|
||||
|
||||
Reference in New Issue
Block a user