Skip to content

Kit Links

Pavel edited this page Oct 21, 2026 · 8 revisions

English | Русский

Ready-made extensions for links between documents and people: wiki links, embedded images, tags, mentions, issue links and a table of contents in place. They are off by default and connected one line each, like the callouts.

The meaning comes from your application. A click on a wiki link, a tag or a mention goes the way of links: the MarkdownLink.Navigate event gets the target wiki:Page#Section, tag:name or mention:name, and your handler opens what it means. Whether a page exists and what a person is called, the extension asks a resolver — IMdLinkResolver, implemented by your application.

Wiki links, a tag, a mention, an issue link and a table of contents

Connecting

MainWindow.xaml (xmlns:md="https://github.com/porohkun/Beresta.Markdown.Wpf" and xmlns:sys="clr-namespace:System;assembly=System.Runtime" on the root element; local:NotesResolver is your resolver):

<md:MarkdownViewer Markdown="{Binding Text}" md:MarkdownLink.Navigate="OnMarkdownLink">
    <md:MarkdownViewer.Extensions>
        <md:WikiLinks Resolver="{x:Static local:NotesResolver.Instance}" />
        <md:WikiEmbeds />
        <md:Tags />
        <md:Mentions Resolver="{x:Static local:NotesResolver.Instance}" />
        <md:IssueLinks>
            <md:IssueLinks.Templates>
                <sys:String x:Key="#">https://github.com/org/repo/issues/{0}</sys:String>
            </md:IssueLinks.Templates>
        </md:IssueLinks>
        <md:TableOfContents />
    </md:MarkdownViewer.Extensions>
</md:MarkdownViewer>

NotesResolver.cs:

using Beresta.Markdown.Wpf.Kit;

public sealed class NotesResolver : IMdLinkResolver
{
    public static NotesResolver Instance { get; } = new();

    public bool PageExists(string page) => page is "Home" or "Roadmap";

    public string? DisplayName(string user) => user == "anna" ? "Anna Smith" : null;
}

Both members have defaults — every page exists, a name stays as written — so implement only what you need.

The extensions ask the resolver while they parse. When its answers change — a page appears, a person gets a name — call Refresh() on the viewer: it builds the same text anew and keeps the selection and the widget states. A resolver that may be called from a background thread is marked IMdBackgroundSafe (using Beresta.Markdown.Wpf.Extensions;): then a long text is parsed in the background — see Live Preview.

MainWindow.xaml.cs, in the window class:

private void OnMarkdownLink(object sender, MarkdownLinkEventArgs e)
{
    if (e.Href.StartsWith("wiki:") || e.Href.StartsWith("tag:") || e.Href.StartsWith("mention:"))
    {
        MessageBox.Show(e.Href);
        e.Handled = true;
    }
}

Wiki links

WikiLinks: [[Page]], [[Page#Section]], [[Page|caption]]. The link is styled text: it is selected by letters and found by search. A page the resolver does not know is drawn with its own look; [[#Section]] leads to a heading of this document.

Any .md file:

See [[Roadmap]], [[Roadmap#Stage 2|the next stage]] and [[#Links]].

Embedded images

WikiEmbeds: ![[file.png]] is an image loaded by the image loader of the viewer; ![[file.png|200]] and ![[file.png|200x100]] give its size in pixels, any other caption is its alt text. An embedded file that is not an image becomes a wiki link to it.

Tags

Tags: #tag and #tag/nested are chips with the target tag:tag. Not a tag: digits only — that is an issue, — # right after a letter or a digit, as in C#, and # inside a link or code.

Mentions

Mentions: @name is a chip with the target mention:name and the name from the resolver. Not a mention: @ right after a letter or a digit, as in an e-mail address, and @ inside a link. The chip is the template Md.Mention.Template of the theme: the background Md.Mention.Background and the text in the color of a link; with a transparent background it looks like a link. Tags have the same background.

Issue links

IssueLinks turns #123, org/repo#45 and PROJ-45 into links by your templates. A template is the prefix exactly as it is written before the number — #, org/repo#, PROJ- — and the address with {0} in place of the number. There are no templates by default, so nothing becomes a link until you add one.

MainWindow.xaml.cs, in the constructor (using Beresta.Markdown.Wpf.Kit;):

var issues = new IssueLinks();
issues.Templates["#"] = "https://github.com/org/repo/issues/{0}";
issues.Templates["PROJ-"] = "https://jira.example.com/browse/PROJ-{0}";
Viewer.Extensions.Add(issues);

Table of contents

TableOfContents: a paragraph of exactly [TOC], [[_TOC_]] or [[toc]] becomes the list of the headings of the document. An item leads to its heading by the #id link, and the list follows the text as it changes.

In the source of the editor

In the editor the brackets of a wiki link or an embed, |, # and the page before a caption are markup; the caption or the page has the look of a link, a missing page — the color of Md.WikiLink.Missing.Style. A tag is a link with the background of its style Md.Tag.Style, a mention — a link with the background Md.Mention.Background.

Look

Key What it is
Md.WikiLink.Style, Md.WikiLink.Missing.Style Span styles of a wiki link and of a link to a page that does not exist; the latter is in the color of danger Md.Callout.Danger.Brush
Md.Tag.Style Span style of a tag; the background is Md.Mention.Background, the text has the color of a link
Md.Mention.Template the template of a mention chip; Md.Mention.Background, .Padding, .CornerRadius; the text has the color of a link Md.Paragraph.LinkForeground
Md.Toc.Template the template of the table of contents; Md.Toc.Margin, Md.Toc.Level1.Margin … Md.Toc.Level6.Margin

«Copy as Markdown» writes wiki links, embeds, tags and issues back in their own syntax, a mention as @name.

Beresta.Markdown.Wpf

Basics

Working with Text

Appearance

Integration

Editing

Your Own Syntax

Ready-made Extensions


По-русски

Основы

Работа с текстом

Оформление

Встраивание в приложение

Правка

Свой синтаксис

Готовые расширения

Clone this wiki locally