Repository navigation
Kit Media
English | Русский
Ready-made extensions for media and data: video cards, emoji shortcodes, Hugo and Jekyll shortcodes,
tables from CSV and a properties card for front matter. Off by default, connected one line each
(xmlns:md="https://github.com/porohkun/Beresta.Markdown.Wpf"), like the
callouts.

MainWindow.xaml:
<md:MarkdownViewer Markdown="{Binding Text}">
<md:MarkdownViewer.Extensions>
<md:VideoCards />
<md:EmojiShortcodes />
<md:Shortcodes />
<md:CsvTables />
<md:PropertiesCard />
</md:MarkdownViewer.Extensions>
</md:MarkdownViewer>VideoCards: an image link to a video on YouTube, Vimeo or RuTube — the way READMEs show videos — is a
card: a preview, the title from the alt text and a play icon. An image whose address is a video is a
card too: YouTube gives a preview by the address of the video, Vimeo and RuTube do not, and their card
has no preview. A click goes the way of links: the Navigate event, then the link
opener.
Any .md file:
[](https://www.youtube.com/watch?v=VIDEO_ID)
The preview is loaded by the image loader of the viewer.
LoadThumbnails="False" keeps cards off the network: a preview from the internet is not loaded, a
local one still is.
<md:VideoCards LoadThumbnails="False" />EmojiShortcodes: GitHub emoji names — :smile:, :rocket:, :white_check_mark: — become emoji.
Smileys like :) stay text.
WPF draws emoji in one color: it has no color fonts, so an emoji takes the color of the text around it.
Shortcodes: {{< name arguments >}} and {{% name arguments %}} of Hugo and {% name arguments %}
of Jekyll are widgets by name. Arguments are divided by spaces, an argument with spaces is quoted,
key=value is a named argument. A shortcode nobody handles stays text.
| Name | Arguments | Becomes |
|---|---|---|
youtube |
the video id, a title | a video card |
vimeo |
the video id, a title | a video card without a preview |
gist |
user/id or user id
|
a link card to the gist |
pdf |
the address | a link card with the file name |
toc |
— | the table of contents in place, when the shortcode is a paragraph of its own |
Any .md file:
{{< youtube VIDEO_ID "Release overview" >}}
{% pdf "docs/guide.pdf" %}
{{< toc >}}Video cards from shortcodes obey LoadThumbnails of Shortcodes, the same as in VideoCards.
The application adds its own names to Handlers. A handler gets the shortcode — the name, the
arguments, the named arguments — and returns the model of a widget: an inline widget goes into the
line, a block widget replaces a paragraph that is this shortcode alone. null leaves the shortcode as
text. With handlers of your own a long text is parsed on the interface thread, unless the object of
each handler's method is marked IMdBackgroundSafe — see
Live Preview.
MainWindow.xaml.cs, in the window constructor after InitializeComponent()
(using Beresta.Markdown.Wpf.Kit;, using Beresta.Markdown.Wpf.ViewModels;):
var shortcodes = new Shortcodes();
shortcodes.Handlers["kbd"] = shortcode => new RunVm(string.Join(" ", shortcode.Arguments), Kbd: true);
Viewer.Extensions.Add(shortcodes);Now {{< kbd Ctrl+Shift+P >}} is a key. Argument(name, index) returns a named argument or, without
it, the argument at that position. A widget with its own model and template is made as in
Extensions.
CsvTables: a code block in csv or tsv is a table, the first row is the header. Values follow the
CSV rules: a value in quotes keeps commas and line breaks, "" inside it is a quote; spaces around a
value without quotes are dropped. Short rows get empty cells up to the widest one.
Any .md file:
```csv
City,Population,"Area, km²"
Moscow,13 010 112,2561
Novosibirsk,1 633 595,502
```It is the usual table of the theme: selected by cells and copied as Markdown as a table. In the source of the editor the block stands in columns by its separators.
PropertiesCard: the front matter at the start of the document is a
«key — value» table: key: value with or without quotes; lists [a, b] and - a lines become one line
with commas; | and > text keeps its lines; anything nested is shown as text. The text of the block is
still in FrontMatter, and parsing YAML for your own needs is up to the application.
Any .md file:
---
title: Release notes
tags: [release, wpf]
author:
name: Ivan
---Copied as Markdown whole, the card gives back the front matter as it is written.
While AreControlsEditable and IsFrontMatterEditable are on, a value is edited by its type, a cross
removes a property, and the last row adds one. Every edit goes through SourceEditRequested, like a
ticked task — see Task Lists; in the editor it gets
into its undo. Nested and multiline values, {…} maps, anchors, aliases and tags are only shown.

| Type | Which values | Edited with | Written |
|---|---|---|---|
Text |
the rest | an input field: Enter and losing focus write the value, Esc returns the written one | the way the old value was written — see below |
Bool |
true, false, yes, no, on, off without quotes |
a check box |
true or false; a value written yes or on — with its own word, in the same case |
Date |
a date yyyy-MM-dd
|
DatePicker |
yyyy-MM-dd without quotes |
List |
[a, b] and - a lines |
chips with a cross and a field for a new item: Enter adds it | the list the way it was written, each item as a plain value while it reads back the same, otherwise in double quotes; an item may hold a comma |
The cross of a row removes all the lines of its property. The row that adds a property takes a key and
writes a line key: before the closing ---; a key with : or # inside or a YAML sign at its start
goes into double quotes, and a key that is already in the card is not added. Markdig reads --- right
after --- as two rules, so an empty front matter keeps a line between them: an empty one or a comment.
MainWindow.xaml:
<md:MarkdownViewer Markdown="{Binding Text, Mode=TwoWay}" AreControlsEditable="True" IsFrontMatterEditable="True">
<md:MarkdownViewer.Extensions>
<md:PropertiesCard />
</md:MarkdownViewer.Extensions>
</md:MarkdownViewer>Fields lists the properties the application knows. The type of a field is stronger than the guess by
the value: a List field shows a plain value as a list of one item and writes it in brackets after the
first change; a field without a type only gives its key. The keys of the fields that are not in the card
yet are suggested by the row that adds a property. A type of your own X is drawn with the template
Md.Properties.X.Template — see Look; without it — as text.
MainWindow.xaml:
<md:MarkdownViewer Markdown="{Binding Text, Mode=TwoWay}" AreControlsEditable="True" IsFrontMatterEditable="True">
<md:MarkdownViewer.Extensions>
<md:PropertiesCard>
<md:PropertiesCard.Fields>
<md:MdPropertyField Key="tags" Type="List" />
<md:MdPropertyField Key="draft" Type="Bool" />
<md:MdPropertyField Key="date" Type="Date" />
<md:MdPropertyField Key="author" />
</md:PropertiesCard.Fields>
</md:PropertiesCard>
</md:MarkdownViewer.Extensions>
</md:MarkdownViewer>A text value is written the way the old one was:
| Was | Written |
|---|---|
key: value |
plain while it is safe, otherwise in double quotes with " and \ escaped; an empty field leaves the key without a value |
key: 'value' |
in single quotes, ' doubled |
key: "value" |
in double quotes |
A plain value is not safe when it starts or ends with a space, has : or # inside, ends with :,
starts with one of -?:,[]{}#&*!|>'"%@ or a backtick, or looks like true, false, null, ~,
yes, no, on, off or a number while the old value did not. A comment after the value stays.
| Key | What it is |
|---|---|
Md.VideoCard.Template |
the template of a video card; Md.VideoCard.Width, .PreviewHeight, .TitlePadding, .PreviewBackground, .PlayBackground, .PlayForeground, .PlaySize, .PlayIcon (Geometry in a square: its proportions and the shift to the optical center are in the geometry), .PlayIconSize
|
Md.VideoCard.PreviewStyle |
MdImage style of the preview |
Md.LinkCard.Template |
the template of a link card; Md.LinkCard.Padding, .Icon, .IconStrokeThickness, the size and the margin of the icon Md.Icon.Size, Md.Icon.Margin; the address looks like a figure caption: Md.Figure.CaptionForeground, Md.Figure.CaptionFontSize
|
Md.Card.CornerRadius |
the rounding of the video card and the link card |
Md.Properties.Template |
the template of the properties card: md:MdPropertiesPresenter with the rows and the row that adds a property; Md.Properties.KeyStyle is the MdTextBlock style of a key |
Md.Properties.Text.Template, .Bool.Template, .Date.Template, .List.Template
|
the templates of a value by its type, chosen by md:MdPropertyValue; the input field is md:MdPropertyBox, shown in place of the value while its IsActive is on, the date — md:MdPropertyDatePicker. A template of your own type writes through the commands of MdPropertiesPresenter: SetValueCommand, AddItemCommand, RemoveItemCommand, RemoveCommand, AddCommand
|
Md.Properties.ChipPadding, .ChipMargin, .ChipCornerRadius
|
the chips of a list; the background is the one of a chip, Md.Chip.Background
|
Md.Properties.RemoveTemplate, .RemoveIcon (Geometry), .RemoveIconSize, .RemoveIconStrokeThickness, .RemovePadding
|
the cross of a row and of a chip |
Md.Properties.Remove, .Add, .AddItem
|
the captions of a cross, of the row that adds a property and of the field for a new item |
The borders of the cards are the ones of a table, Md.Table.BorderBrush and Md.Table.BorderThickness; the
key column of the properties card is Md.Table.HeaderBackground.
Beresta.Markdown.Wpf · Issues · MIT License
Basics
- Getting Started
- How It Renders
- Supported Markdown
- Settings and Hooks
- Scrolling and Virtualization
- Comparison
Working with Text
Appearance
Integration
- Application Links
- Images
- Untrusted Text
- Task Lists
- Source Lines and Two Panes
- Coordinates
- Live Preview
Editing
Your Own Syntax
Ready-made Extensions
Основы
- Начало работы
- Как рисует вьюер
- Что поддерживается
- Настройки и перехват
- Прокрутка и виртуализация
- Сравнение
Работа с текстом
Оформление
Встраивание в приложение
- Ссылки приложения
- Картинки
- Чужой текст
- Списки задач
- Строки исходника и две панели
- Координаты
- Живой предпросмотр
Правка
Свой синтаксис
Готовые расширения