Alternative markup syntax proposal.
See original GitHub issueSince the very first thing XamlIl does is conversion of XML to its own AST, we can now create other markup languages relatively cheaply by simply writing a parser that produces the same AST.
Since some people seem to hate XML, here is a non-XML markup proposal:
// Default namespaces for Avalonia, x: and d: are omitted here and added automatically
using local = clr MyNamespace
using lib = xml http://some.lib/xml/namespace
Window
{
StackPanel
{
// Equivalent of <Button>
Button
// Unless followed by = before the end of line, in this case it's a property assignment
Orientation = "Horizontal"
Attached.Property="Value"
// This is an equivalent of <Button Background="Red">Click me</Button>
Button
{
"Click me"
Background = "Red"
}
local:MyControl
lib:LibraryControl
clr:System.Collections.Generic.List<clr:System.Int32> {
1
2
3 4 5 6
}
// Markup extensions are prefixed by $
TextBlock { Text = ${Binding SomeVmProp} }
// $-prefixed strings are a shortcut to {Binding ...}
TextBlock { x:Name = "Name" Text = $"SomeVmProp" }
TextBlock { Text = $"#Name.Text, Mode=TwoWay" }
TextBlock {
"Plain text"
Run { Background="Red" "Text" FontFamily="Tahoma" }
"Plain text"
}
}
Styles =
{
// Styles property is treated in specific way, all root elements are considered to be <Style Selector="{LINE}"> to reduce boilerplate
StackPanel > is:(Control).someClass:pointerover
{
Margin = "0 0 1 4"
}
Button
{
Template =
{
// ControlTemplate is omitted here and is assumed by default. We can probably do the same for regular XAML
ContentPresenter
{
Name = "PART_ContentPresenter"
Background = ${TemplateBinding Background}
TextBlock.Foreground = ${TemplateBinding Foreground}
}
}
}
}
}
XAML for comparison:
<Window
xmlns="https://github.com/avaloniaui"
xmlns:local="clr-namespace:MyNamespace"
xmlns:lib="http://some.lib/xml/namespace"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:scg="clr-namespace:System.Collections.Generic;assembly=netstandard">
xmlns:sys="clr-namespace:System;assembly=netstandard">
<StackPanel
Orientation="Horizontal" Attached.Property="Value">
<Button>
<Button Background="Red">
Click me
</Button>
<local:MyControl/>
<lib:LibraryControl/>
<scg:List x:TypeArguments="sys:Int32">
<x:Int32>1</x:Int32>
<x:Int32>2</x:Int32>
<x:Int32>3</x:Int32>
<x:Int32>4</x:Int32>
<x:Int32>5</x:Int32>
<x:Int32>6</x:Int32>
</scg:List>
<TextBlock Text="{Binding SomeVmProp}"/>
<TextBlock x:Name="Name" Text="{Binding SomeVmProp}"/>
<TextBlock Text="{Binding #Name.Text, Mode=TwoWay}"/>
<TextBlock>
Plain text
<Run Background="Red" FontFamily="Tahoma">Text</Run>
Plain text
</TextBlock>
</StackPanel>
<Window.Styles>
<Style Selector="StackPanel > is:(Control).someClass:pointerover">
<Setter Property="Margin" Value="0 0 1 4"/>
</Style>
<Style Selector="Button">
<Setter Property="Template">
<ControlTemplate>
<ContentPresenter
Name="PART_ContentPresenter"
Background = "{TemplateBinding Background}"
TextBlock.Foreground = "{TemplateBinding Foreground}"/>
</ControlTemplate>
</Setter>
</Style>
</Window.Styles>
</Window>
Issue Analytics
- State:
- Created 4 years ago
- Reactions:36
- Comments:31 (20 by maintainers)
Top Results From Across the Web
Markdown vs. alternatives for software documentation
How to choose among Markdown, reStructuredText, Asciidoc, and Org-mode for your software project documentation.
Read more >Our favorite markup languages for documentation
Our favorite markup languages for documentation ; HTML. 6% (25 votes) ; reStructuredText. 5% (23 votes) ; AsciiDoc. 13% (57 votes) ; Markdown....
Read more >A proposal to support the <mark> tag with Markdown
As I was thinking about the <mark> tag, I realized that it could be supported without a Markdown syntax change, by taking advantage...
Read more >Basic Syntax
Nearly all Markdown applications support the basic syntax outlined in the original Markdown design document. There are minor variations and discrepancies ...
Read more >What is the best markdown alternative?
If you mean the most complete (books, etc), I think the best alternatives are AsciiDoc , Pandoc and reStructuredText . But if you...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The “Blazor” syntax is a really cool concept too. https://github.com/microsoft/microsoft-ui-xaml/issues/2499 “Proposal: Support Blazor Syntax”
The link to the video where some ideas were presented today by the Uno Platform is below (time 56:14) https://youtu.be/TeS4rX3i_Ls?t=3374
Yes, I’m seeding this all over the place because it’s awesome!
I prefer the XAML syntax.