question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Alternative markup syntax proposal.

See original GitHub issue

Since 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:open
  • Created 4 years ago
  • Reactions:36
  • Comments:31 (20 by maintainers)

github_iconTop GitHub Comments

12reactions
robloocommented, Jul 17, 2021

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!

image

9reactions
TonyHenriquecommented, Jun 6, 2019

I prefer the XAML syntax.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found