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

What is the proper way to gain control over Markdown font size, codeblock style, etc? #14

Open
wellinthatcase opened this issue Dec 22, 2020 · 2 comments

Comments

@wellinthatcase
Copy link

Within this snippet of markdown for example,

<mdxam:MarkdownScrollViewer xml:space="preserve" 
                            x:Name="MarkdownPeer" Background="Transparent" 
                            VerticalScrollBarVisibility="Hidden"
                            Margin="16,37,0,0" 
                            Visibility="Hidden" 
                            Foreground="#FFF2EEE5" 
                            FontSize="18">
            null
</mdxam:MarkdownScrollViewer>

Programmatically adding markdown, e.g

TextRange rng = new TextRange(
    TextEntry.Document.ContentStart,
    TextEntry.Document.ContentEnd);
    
MarkdownScrollViewer.Markdown = rng.Text; 

Results in inconsistent Markdown. Here's a few things I noticed in my usage:

  1. Headers do not conform to the MarkdownScrollViewer's Foreground, thus remain black.
  2. Markdown does not conform to MarkdownScrollViewer's Font properties, most notably, font size.
  3. Codeblocks also negate MarkdownScrollViewer's properties, and remain independent.
  4. Lists seem to form a margin and end up being formatted ~50px to the right of where expected.

This could be a result of my (probably) improper usage. How should we go about controlling styling of the Markdown in further depth?

@whistyun
Copy link
Owner

MarkdownScrollViewer has MarkdownStyle property. It can change style for each control in Markdown.
Unfortunately, In current version, I don't provide way to apply additional style, so We should set style for all control.

Styles are identified by the type of control and the value of the tag and applied to each control.
For example Heading1/Heading2 is Paragraph which has "Heading1"/"Heading2" tag.

<mdxam:MarkdownScrollViewer xml:space="preserve">

    # Heading 1
    
    ## Heading 2
    
    content

    <mdxam:MarkdownScrollViewer.MarkdownStyle>
        <Style TargetType="FlowDocument">
            <Style.Resources>
                <Style TargetType="Paragraph">
                    <Style.Triggers>
                        <Trigger Property="Tag" Value="Heading1">
                            <Setter Property="FontSize"   Value="42" />
                            <Setter Property="Foreground" Value="Red" />
                            <Setter Property="FontWeight" Value="Light" />
                        </Trigger>

                        <Trigger Property="Tag" Value="Heading2">
                            <Setter Property="FontSize"   Value="20" />
                            <Setter Property="Foreground" Value="Blue" />
                            <Setter Property="FontWeight" Value="Light" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </Style.Resources>
        </Style>
    </mdxam:MarkdownScrollViewer.MarkdownStyle>
</mdxam:MarkdownScrollViewer>

If you want to make from the existing style, see Markdown.Style.xaml.

@whistyun
Copy link
Owner

I forgot Style.Based On property.
We can include the build-in style to custom style.

<mdxam:MarkdownScrollViewer.MarkdownStyle>
    <Style 
        TargetType="FlowDocument"
        BasedOn="{x:Static mdxam:MarkdownStyle.Standard}">
        <Style.Resources>
            <Style TargetType="Paragraph">
                <Setter Property="Margin" Value="4, 2, 0, 6"/>
                <Style.Triggers>
                    <Trigger Property="Tag" Value="Heading1">
                        <Setter Property="FontSize"   Value="42" />
                        <Setter Property="Foreground" Value="Red" />
                        <Setter Property="FontWeight" Value="Light" />
                        <Setter Property="Margin" Value="0"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </Style.Resources>
    </Style>
</mdxam:MarkdownScrollViewer.MarkdownStyle>

image

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