From 99b35c0aaf5a2e1eb86592a264fa893740249048 Mon Sep 17 00:00:00 2001 From: Elias Fierke Date: Tue, 13 Jan 2026 18:33:35 +0100 Subject: [PATCH] [feat:] forgot to git-add the wiki source files... here they are --- Wiki/EditorWindow.axaml | 8 +++ Wiki/EditorWindow.axaml.cs | 17 +++++ Wiki/MarkdownRenderer.cs | 126 +++++++++++++++++++++++++++++++++ Wiki/NamePromptWindow.axaml | 13 ++++ Wiki/NamePromptWindow.axaml.cs | 26 +++++++ Wiki/WikiItem.cs | 13 ++++ Wiki/WikiService.cs | 76 ++++++++++++++++++++ 7 files changed, 279 insertions(+) create mode 100644 Wiki/EditorWindow.axaml create mode 100644 Wiki/EditorWindow.axaml.cs create mode 100644 Wiki/MarkdownRenderer.cs create mode 100644 Wiki/NamePromptWindow.axaml create mode 100644 Wiki/NamePromptWindow.axaml.cs create mode 100644 Wiki/WikiItem.cs create mode 100644 Wiki/WikiService.cs diff --git a/Wiki/EditorWindow.axaml b/Wiki/EditorWindow.axaml new file mode 100644 index 0000000..580ba78 --- /dev/null +++ b/Wiki/EditorWindow.axaml @@ -0,0 +1,8 @@ + + + The editor feature has been disabled. The Edit button remains for UI compatibility. + + diff --git a/Wiki/EditorWindow.axaml.cs b/Wiki/EditorWindow.axaml.cs new file mode 100644 index 0000000..a645229 --- /dev/null +++ b/Wiki/EditorWindow.axaml.cs @@ -0,0 +1,17 @@ +using System; +using Avalonia.Controls; + +namespace Logof_Client.Wiki; + +public partial class EditorWindow : Window +{ + private void InitializeComponent() + { + Avalonia.Markup.Xaml.AvaloniaXamlLoader.Load(this); + } + + public EditorWindow() + { + InitializeComponent(); + } +} diff --git a/Wiki/MarkdownRenderer.cs b/Wiki/MarkdownRenderer.cs new file mode 100644 index 0000000..c7396f3 --- /dev/null +++ b/Wiki/MarkdownRenderer.cs @@ -0,0 +1,126 @@ +using System.Collections.Generic; +using Avalonia.Controls; +using Avalonia.Media; +using Markdig; +using Markdig.Syntax; +using Markdig.Syntax.Inlines; +using System.Text; + +namespace Logof_Client.Wiki; + +public static class MarkdownRenderer +{ + public static Control Render(string markdown) + { + var panel = new StackPanel { Spacing = 6 }; + if (string.IsNullOrWhiteSpace(markdown)) return panel; + + var doc = Markdown.Parse(markdown); + + foreach (var block in doc) + { + switch (block) + { + case HeadingBlock hb: + { + var text = GetInlineText(hb.Inline); + var tb = new TextBlock + { + Text = text, + FontWeight = FontWeight.Bold, + Margin = new Avalonia.Thickness(0, hb.Level == 1 ? 6 : 2, 0, 2) + }; + tb.FontSize = hb.Level switch { 1 => 22, 2 => 18, 3 => 16, _ => 14 }; + panel.Children.Add(tb); + break; + } + + case ParagraphBlock pb: + { + var text = GetInlineText(pb.Inline); + var tb = new TextBlock { Text = text, TextWrapping = Avalonia.Media.TextWrapping.Wrap }; + panel.Children.Add(tb); + break; + } + + case FencedCodeBlock cb: + { + var sb = new StringBuilder(); + foreach (var line in cb.Lines.Lines) + { + sb.Append(line.ToString()); + } + var codeBox = new TextBox + { + Text = sb.ToString(), + FontFamily = "Consolas, monospace", + IsReadOnly = true, + AcceptsReturn = true + }; + panel.Children.Add(codeBox); + break; + } + + case ListBlock lb: + { + var sp = new StackPanel { Spacing = 2 }; + var number = 1; + foreach (var item in lb) + { + if (item is ListItemBlock lib) + { + var itemText = new StringBuilder(); + foreach (var sub in lib) + { + if (sub is ParagraphBlock pp) + itemText.Append(GetInlineText(pp.Inline)); + } + var tb = new TextBlock { Text = (lb.IsOrdered ? (number++ + ". ") : "• ") + itemText.ToString() }; + sp.Children.Add(tb); + } + } + panel.Children.Add(sp); + break; + } + + default: + { + // fallback: raw text + panel.Children.Add(new TextBlock { Text = block.ToString() }); + break; + } + } + } + + return panel; + } + + private static string GetInlineText(ContainerInline? container) + { + if (container == null) return string.Empty; + var sb = new StringBuilder(); + foreach (var inline in container) + { + switch (inline) + { + case LiteralInline li: + sb.Append(li.Content.ToString()); + break; + case EmphasisInline ei: + sb.Append(GetInlineText(ei)); + break; + case CodeInline ci: + sb.Append(ci.Content); + break; + case LinkInline li: + sb.Append(GetInlineText(li)); + break; + default: + sb.Append(inline.ToString()); + break; + } + } + + return sb.ToString(); + } +} diff --git a/Wiki/NamePromptWindow.axaml b/Wiki/NamePromptWindow.axaml new file mode 100644 index 0000000..d48dd86 --- /dev/null +++ b/Wiki/NamePromptWindow.axaml @@ -0,0 +1,13 @@ + + + + + +