Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different code styles #65

Open
GilbertoTheMighty opened this issue Jun 10, 2023 · 4 comments
Open

Different code styles #65

GilbertoTheMighty opened this issue Jun 10, 2023 · 4 comments

Comments

@GilbertoTheMighty
Copy link

How to configure syntax style for different codeBlock languages?

<mdxam:MarkdownScrollViewer x:Name="Markdownview"
                                                            HorizontalAlignment="Center" Foreground="White" VerticalAlignment="Stretch"
                                                            VerticalScrollBarVisibility="Disabled" Markdown="{Binding content}" Grid.Column="1" Margin="20,20,20,20" PreviewMouseWheel="Markdownview_MouseWheel">
                                    <mdxam:MarkdownScrollViewer.MarkdownStyle>
                                        <Style TargetType="FlowDocument" BasedOn="{x:Static mdxam:MarkdownStyle.Sasabune}">
                                            <Style.Resources>
                                                <Style TargetType="Paragraph">
                                                    <Style.Triggers>
                                                        <Trigger Property="Tag" Value="Heading1">
                                                            <Setter Property="FontSize" Value="42" />
                                                        </Trigger>

                                                        <Trigger Property="Tag" Value="Heading2">
                                                            <Setter Property="FontSize" Value="20" />
                                                        </Trigger>

                                                        <Trigger Property="Tag" Value="CodeBlock">
                                                            <Setter Property="Margin" Value="15"/>
                                                            <Setter Property="Padding" Value="15"/>
                                                        </Trigger>
                                                    </Style.Triggers>
                                                </Style>
                                                <Style TargetType="Hyperlink">
                                                    <Setter Property="TextDecorations" Value="None" />
                                                </Style>
                                            </Style.Resources>
                                        </Style>
                                    </mdxam:MarkdownScrollViewer.MarkdownStyle>
                                </mdxam:MarkdownScrollViewer>
@GilbertoTheMighty
Copy link
Author

image
c# code is not highlighted,

@whistyun
Copy link
Owner

whistyun commented Jun 11, 2023

What lang-code do you use for codeblock?
For now, MdXaml recognizes only cs to display C# code.

The bellow code is highlighted.
```cs
using System;
class Main{}
```

The bellow code is not highlighted.
```csharp
using System;
class Main{}
```

@GilbertoTheMighty
Copy link
Author

Thank you! Using replace on incoming string did the trick.
How can I configure styles for different langs in codeblock?

whistyun added a commit that referenced this issue Jun 25, 2023
whistyun added a commit that referenced this issue Jun 28, 2023
@whistyun
Copy link
Owner

MdXaml v1.20.1 has been released.
This version enables the addition of syntax highlighting rules.

To add syntax highlighting, use MdXamlPlugins.Highlights.

sample: App.xaml

<!-- xmlns:mdplugins="clr-namespace:MdXaml.Plugins;assembly=MdXaml.Plugins" -->

<Application ...>
  <Application.Resources>
    <mdplugins:MdXamlPlugins x:Key="MdXamlPlugins">
      <mdplugins:MdXamlPlugins.Highlights>

        <!-- 
          Create a new alias from the xshd file.
          Multiple alias names can be indicated by separating them with ",".
          In this case pegasus and peg.
        -->
        <mdplugins:Definition Alias="pegasus,peg"   Resource="pack://application:,,,/Asset/Pegasus-Mode.xshd" />

        <!--
          Alias an already defined langcode (in this case javascript).
        -->
        <mdplugins:Definition Alias="typescript,ts" RealName="javascript" />

      </mdplugins:MdXamlPlugins.Highlights>
    </mdplugins:MdXamlPlugins>
  </Application.Resources>
</Application>

markdown sample

```peg
@namespace PegExamples
@classname SignificantWhitespaceParser
@using System.Linq

program <object>
  = s:"Hello" {s}
```

===

```ts
const message="Hello world!"
console.log(message)
```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants