whistyun / Markdown.Avalonia

render markdown with Avalonia UI
MIT License
301 stars 24 forks source link

no effect when using style #69

Closed dayAndnight2018 closed 2 years ago

dayAndnight2018 commented 2 years ago

I want to write annotations in CodeBlock, set the fontfamily style and MonospaceFontFamily style but no work.

dayAndnight2018 commented 2 years ago

``

dayAndnight2018 commented 2 years ago

``

whistyun commented 2 years ago

Are you trying to apply a style to syntax-highlighting code block? For syntax-highlighting code block, a style should be apply to TextEditor in AvaloniaEdit.


<!--
xmlns:md="clr-namespace:Markdown.Avalonia;assembly=Markdown.Avalonia"
xmlns="https://github.com/avaloniaui"
xmlns:avedit="https://github.com/avaloniaui/avaloniaedit"
xmlns:ctxt="clr-namespace:ColorTextBlock.Avalonia;assembly=ColorTextBlock.Avalonia"
-->

<md:MarkdownScrollViewer>
  <md:MarkdownScrollViewer.Styles>
    <Style Selector="ctxt|CCode">
      <Style.Setters>
        <Setter Property="MonospaceFontFamily" Value="Niagara Solid" />
        <Setter Property="FontSize" Value="20" />
      </Style.Setters>
    </Style>

    <Style Selector="TextBlock.CodeBlock">
      <Style.Setters>
        <Setter Property="FontFamily" Value="MV Boli" />
      </Style.Setters>
    </Style>

    <Style Selector="avedit|TextEditor">
      <Setter Property="FontFamily" Value="Old English Text MT" />
    </Style>
  </md:MarkdownScrollViewer.Styles>

  Sample:

  ``Code Span``

  ---

// TextBlock.CodeBlock //

int main(){ return 0; }


  ---

  ```c
  // AvaloniaEdit.TextEditor //

  int main(){
    return 0;
  }

</md:MarkdownScrollViewer>


![image](https://user-images.githubusercontent.com/13712028/164716438-6258e5a8-de9e-4194-880a-76a4f83a0c72.png)
dayAndnight2018 commented 2 years ago

Thanks a lot, that works now