Skip to content

Commit

Permalink
Merge branch 'main' into opacitymaskview-experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
h82258652 authored Dec 2, 2024
2 parents 966d7ef + b71dbf1 commit d80eb50
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
</ItemGroup>
<ItemGroup>
<!--<PackageReference Include="ColorCode.Core" Version="2.0.14" />-->
<PackageReference Include="HtmlAgilityPack" Version="1.11.48" />
<PackageReference Include="Markdig" Version="0.31.0" />
<PackageReference Include="Roman-Numerals" Version="2.0.0" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.71" />
<PackageReference Include="Markdig" Version="0.38.0" />
<PackageReference Include="Roman-Numerals" Version="2.0.1" />
</ItemGroup>
<ItemGroup Condition="'$(IsUwp)' == 'true'">
<Using Include="Windows.UI" />
Expand Down
17 changes: 15 additions & 2 deletions components/MarkdownTextBlock/src/MarkdownTextBlock.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using CommunityToolkit.Labs.WinUI.MarkdownTextBlock.Renderers;
using CommunityToolkit.Labs.WinUI.MarkdownTextBlock.TextElements;
using Markdig;
using Markdig.Syntax;

namespace CommunityToolkit.Labs.WinUI.MarkdownTextBlock;

Expand All @@ -30,6 +31,12 @@ public partial class MarkdownTextBlock : Control
typeof(MarkdownTextBlock),
new PropertyMetadata(null, OnTextChanged));

private static readonly DependencyProperty MarkdownDocumentProperty = DependencyProperty.Register(
nameof(MarkdownDocument),
typeof(MarkdownDocument),
typeof(MarkdownTextBlock),
new PropertyMetadata(null));

public MarkdownConfig Config
{
get => (MarkdownConfig)GetValue(ConfigProperty);
Expand All @@ -42,6 +49,12 @@ public string Text
set => SetValue(TextProperty, value);
}

public MarkdownDocument? MarkdownDocument
{
get => (MarkdownDocument)GetValue(MarkdownDocumentProperty);
private set => SetValue(MarkdownDocumentProperty, value);
}

public event EventHandler<LinkClickedEventArgs>? OnLinkClicked;

internal void RaiseLinkClickedEvent(Uri uri) => OnLinkClicked?.Invoke(this, new LinkClickedEventArgs(uri));
Expand Down Expand Up @@ -102,8 +115,8 @@ private void ApplyText(bool rerender)

if (!string.IsNullOrEmpty(Text))
{
var markdown = Markdown.Parse(Text, _pipeline);
_renderer.Render(markdown);
this.MarkdownDocument = Markdown.Parse(Text, _pipeline);
_renderer.Render(this.MarkdownDocument);
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions components/MarkdownTextBlock/src/MarkdownThemes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public sealed class MarkdownThemes : DependencyObject

public FontWeight H6FontWeight { get; set; } = FontWeights.Normal;

public Thickness H1Margin { get; set; } = new(0);
public Thickness H2Margin { get; set; } = new(0);
public Thickness H3Margin { get; set; } = new(0);
public Thickness H4Margin { get; set; } = new(0);
public Thickness H5Margin { get; set; } = new(0);
public Thickness H6Margin { get; set; } = new(0);
public Thickness H1Margin { get; set; } = new(left: 0, top: 14, right: 0, bottom: 0);
public Thickness H2Margin { get; set; } = new(left: 0, top: 14, right: 0, bottom: 0);
public Thickness H3Margin { get; set; } = new(left: 0, top: 14, right: 0, bottom: 0);
public Thickness H4Margin { get; set; } = new(left: 0, top: 14, right: 0, bottom: 0);
public Thickness H5Margin { get; set; } = new(left: 0, top: 8, right: 0, bottom: 0);
public Thickness H6Margin { get; set; } = new(left: 0, top: 8, right: 0, bottom: 0);

public Brush InlineCodeBackground { get; set; } = (Brush)Application.Current.Resources["ExpanderHeaderBackground"];
public Brush InlineCodeForeground { get; set; } = (Brush)Application.Current.Resources["TextFillColorPrimaryBrush"];
Expand Down
7 changes: 5 additions & 2 deletions components/MarkdownTextBlock/src/TextElements/MyList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ public MyList(ListBlock listBlock)
}

_stackPanel.Orientation = Orientation.Vertical;
_stackPanel.Margin = new Thickness(left: 0, top: 8, right: 0, bottom: 8);
_container.Child = _stackPanel;
_paragraph.Inlines.Add(_container);
}

public void AddChild(IAddChild child)
{
var grid = new Grid();
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) });
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(20, GridUnitType.Pixel) });
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(10, GridUnitType.Pixel) });
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
string bullet;
if (_isOrdered)
Expand All @@ -79,11 +81,12 @@ public void AddChild(IAddChild child)
};
textBlock.SetValue(Grid.ColumnProperty, 0);
textBlock.VerticalAlignment = VerticalAlignment.Top;
textBlock.TextAlignment = TextAlignment.Right;
grid.Children.Add(textBlock);
var flowDoc = new MyFlowDocument();
flowDoc.AddChild(child);

flowDoc.RichTextBlock.SetValue(Grid.ColumnProperty, 1);
flowDoc.RichTextBlock.SetValue(Grid.ColumnProperty, 2);
flowDoc.RichTextBlock.Padding = new Thickness(0);
flowDoc.RichTextBlock.VerticalAlignment = VerticalAlignment.Top;
grid.Children.Add(flowDoc.RichTextBlock);
Expand Down
16 changes: 8 additions & 8 deletions components/MarkdownTextBlock/src/TextElements/MyThematicBreak.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ public MyThematicBreak(ThematicBreakBlock thematicBreakBlock)
_paragraph = new Paragraph();

var inlineUIContainer = new InlineUIContainer();
var border = new Border();
border.Width = 500;
border.BorderThickness = new Thickness(1);
border.Margin = new Thickness(0, 4, 0, 4);
border.BorderBrush = new SolidColorBrush(Colors.Gray);
border.Height = 1;
border.HorizontalAlignment = HorizontalAlignment.Stretch;
inlineUIContainer.Child = border;
Line line = new Line
{
Stretch = Stretch.Fill,
Stroke = new SolidColorBrush(Colors.Gray),
X2 = 1,
Margin = new Thickness(0, 12, 0, 12)
};
inlineUIContainer.Child = line;
_paragraph.Inlines.Add(inlineUIContainer);
}

Expand Down

0 comments on commit d80eb50

Please sign in to comment.