Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

Make Wpf Markdown Presenter

БесплатноБез исполняемых скриптовНе проверен

Generates a WPF MarkdownPresenter: a ContentControl with a bindable Markdown dependency property that parses Markdig into a FlowDocument and hosts it in a…

christian289от christian289★ 42 звезды на GitHub

Об этом скилле

WPF Markdown Presenter Generator

If $0 is empty, use the AskUserQuestion tool to ask: "Enter the presenter control name (e.g., MarkdownPresenter, ChatMarkdownView)". Do NOT proceed until a valid name is provided. Use the response as the control name for all subsequent steps.

Generate a $0 control: a ContentControl with a bindable Markdown dependency property that parses markdown with Markdig, builds a WPF FlowDocument, and hosts it in a selectable, content-hugging read-only RichTextBox.

  • Replace {Namespace} with the project's root namespace detected from csproj or existing code.
  • Replace {Project} with the target project path (a WPF Application or WPF control library — must have UseWPF).

The full rationale for every choice below is in two knowledge topics — fetch with WpfDevPackMcp get_wpf_topic: rendering-markdown-in-wpf (the AST→FlowDocument dispatcher, the "never ToString() a node" rule, the Block/Inline aliasing, Hyperlink scheme validation) and displaying-selectable-rich-text-in-wpf (the read-only RichTextBox host, the content-hugging HuggingRichTextBox, MouseWheel forwarding, streaming throttle).

Usage

/wpf-dev-pack:make-wpf-markdown-presenter MarkdownPresenter

Required Packages

<PackageReference Include="Markdig" Version="1.*" />
  • Markdig is required (markdown parsing). Verify the current version and the exact API surface with HandMirror before emitting (inspect_nuget_package / inspect_nuget_package_type on Markdig), since the AST node type names drive the switch.
  • The code uses the WPF-UI (Wpf.Ui) theme-brush keys TextFillColorPrimaryBrush / TextFillColorSecondaryBrush via SetResourceReference, and a Wpf.Ui.Controls.Button for the code-block Copy button. If WPF-UI is not installed, swap those for stock WPF (SystemColors.ControlTextBrushKey resource reference, and a plain System.Windows.Controls.Button). See integrating-wpfui-fluent for the brush keys.

Generated Code

$0.cs

The three using-aliases at the top are mandatory — Markdig.Syntax.Block and System.Windows.Documents.Block (and the two Inline types) collide (CS0104), so both must be aliased in any file that both parses markdown and builds a FlowDocument.

using System.Diagnostics;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using Markdig;
using Markdig.Syntax;
using Markdig.Syntax.Inlines;

using MarkdigBlock  = Markdig.Syntax.Block;            // markdown AST node
using MarkdigInline = Markdig.Syntax.Inlines.Inline;   // markdown AST inline
using FlowBlock     = System.Windows.Documents.Block;  // FlowDocument node

namespace {Namespace}.Controls;

/// <summary>
/// A ContentControl that renders a bound Markdown string as a selectable WPF
/// FlowDocument hosted in a read-only RichTextBox. Unhandled Markdig AST nodes
/// are recursed (Container), degraded to inlines/lines (Leaf), or skipped —
/// never ToString()'d (the default ToString returns the type name).
/// </summary>
public sealed class $0 : ContentControl
{
    private static readonly MarkdownPipeline _pipeline =
        new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();

    public static readonly DependencyProperty MarkdownProperty =
        DependencyProperty.Register(nameof(Markdown), typeof(string), typeof($0),
            new PropertyMetadata(null, OnMarkdownChanged));

    public string? Markdown
    {
        get => (string?)GetValue(MarkdownProperty);
        set => SetValue(MarkdownProperty, value);
    }

    // Coalesce re-renders during fast streaming instead of rebuilding per token.
    private readonly DispatcherTimer _renderTimer =
        new() { Interval = TimeSpan.FromMilliseconds(50) }; // ~20 Hz

    public $0()
    {
        _renderTimer.Tick += (_, _) => { _renderTimer.Stop(); Render(Markdown); };
    }

    private static void OnMarkdownChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        var self = ($0)d;
        self._renderTimer.Stop();
        self._renderTimer.Start(); // debounce: render once the burst settles
    }

    // Render: parse markdown -> build a FlowDocument -> host it in a read-only RichTextBox.
    private void Render(string? markdown)
    {
        if (string.IsNullOrEmpty(markdown)) { Content = null; return; }

        var doc = new FlowDocument { PagePadding = new Thickness(0), FontSize = 14 };
        foreach (MarkdigBlock block in Markdig.Markdown.Parse(markdown, _pipeline))
        {
            FlowBlock? b = RenderBlock(block);
            if (b is not null) { doc.Blocks.Add(b); }
        }

        var host = new HuggingRichTextBox
        {
            Document = doc,
            IsReadOnly = true,          // selection + Ctrl+C; no editing, no caret
            IsDoc
Полный SKILL.md на GitHub

Установить Make Wpf Markdown Presenter в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл Make Wpf Markdown Presenter?

Generates a WPF MarkdownPresenter: a ContentControl with a bindable Markdown dependency property that parses Markdig into a FlowDocument and hosts it in a selectable, content-hugging read-only RichTextBox. Use when rendering LLM/chat markdown output as selectable rich text in WPF, or when building a chat/markdown view. Usage: /wpf-dev-pack:make-wpf-markdown-presenter <Name>

Как установить скилл Make Wpf Markdown Presenter?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл Make Wpf Markdown Presenter запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить Make Wpf Markdown Presenter с