mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-07-13 09:18:01 +02: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()
|
.UseEmphasisExtras()
|
||||||
.Build();
|
.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(
|
private static void ProcessInline(
|
||||||
InlineCollection inlines,
|
InlineCollection inlines,
|
||||||
MarkdownInline markdownInline,
|
MarkdownInline markdownInline,
|
||||||
@@ -83,13 +91,7 @@ public class MarkdownToInlinesConverter : IValueConverter
|
|||||||
{
|
{
|
||||||
inlines.Add(
|
inlines.Add(
|
||||||
new InlineUIContainer(
|
new InlineUIContainer(
|
||||||
new HyperLink
|
new HyperLink { Text = GetPlainText(link), Url = link.Url }
|
||||||
{
|
|
||||||
Text = string.Concat(
|
|
||||||
link.OfType<LiteralInline>().Select(l => l.Content.ToString())
|
|
||||||
),
|
|
||||||
Url = link.Url,
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -147,15 +149,7 @@ public class MarkdownToInlinesConverter : IValueConverter
|
|||||||
inlines.Add(new LineBreak());
|
inlines.Add(new LineBreak());
|
||||||
isFirst = false;
|
isFirst = false;
|
||||||
|
|
||||||
var bulletChar = list.BulletType switch
|
var prefix = list.IsOrdered ? $"{itemOrder++}. " : $"{list.BulletType} ";
|
||||||
{
|
|
||||||
BulletType.Dash => '-',
|
|
||||||
BulletType.Plus => '+',
|
|
||||||
BulletType.Asterisk => '*',
|
|
||||||
_ => '-'
|
|
||||||
};
|
|
||||||
|
|
||||||
var prefix = list.IsOrdered ? $"{itemOrder++}. " : $"{bulletChar} ";
|
|
||||||
inlines.Add(new Run(prefix));
|
inlines.Add(new Run(prefix));
|
||||||
|
|
||||||
foreach (var subBlock in listItem.OfType<ParagraphBlock>())
|
foreach (var subBlock in listItem.OfType<ParagraphBlock>())
|
||||||
|
|||||||
Reference in New Issue
Block a user