Skip to content

Commit 0fa9333

Browse files
author
Juan Osorio
committed
Merge branch 'main' into user/juosori/ConfigureBuiltInExtensions
2 parents 255721c + 501882d commit 0fa9333

20 files changed

+178
-69
lines changed

.github/workflows/build.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ on:
1818

1919
env:
2020
DOTNET_VERSION: ${{ '8.0.201' }}
21+
DOTNET_INSTALL_DIR: dotnet-install
22+
DOTNET_ROOT: dotnet-install
2123
ENABLE_DIAGNOSTICS: false
2224
#COREHOST_TRACE: 1
2325
MSBUILD_VERBOSITY: normal
@@ -257,9 +259,19 @@ jobs:
257259
with:
258260
vs-version: '[17.9,)'
259261

262+
- name: Define excluded MultiTargets (WinUI 2)
263+
if: ${{ matrix.winui == '2' }}
264+
run: |
265+
echo "EXCLUDED_MULTITARGETS=wasdk" >> $env:GITHUB_ENV
266+
267+
- name: Define excluded MultiTargets (WinUI 3)
268+
if: ${{ matrix.winui == '3' }}
269+
run: |
270+
echo "EXCLUDED_MULTITARGETS=uwp" >> $env:GITHUB_ENV
271+
260272
# Build and pack component nupkg
261273
- name: Build and pack component packages
262-
run: ./tooling/Build-Toolkit-Components.ps1 -MultiTargets all -WinUIMajorVersion ${{ matrix.winui }} -DateForVersion ${{ env.VERSION_DATE }} ${{ env.VERSION_PROPERTY != '' && format('-PreviewVersion "{0}"', env.VERSION_PROPERTY) || '' }} ${{ env.ENABLE_DIAGNOSTICS == 'true' && '-EnableBinlogs' || '' }} ${{ env.ENABLE_DIAGNOSTICS == 'true' && '-Verbose' || '' }} -BinlogOutput ./ -NupkgOutput ./ -Release
274+
run: ./tooling/Build-Toolkit-Components.ps1 -MultiTargets all -ExcludeMultiTargets ${{ env.EXCLUDED_MULTITARGETS }} -WinUIMajorVersion ${{ matrix.winui }} -DateForVersion ${{ env.VERSION_DATE }} ${{ env.VERSION_PROPERTY != '' && format('-PreviewVersion "{0}"', env.VERSION_PROPERTY) || '' }} ${{ env.ENABLE_DIAGNOSTICS == 'true' && '-EnableBinlogs' || '' }} ${{ env.ENABLE_DIAGNOSTICS == 'true' && '-Verbose' || '' }} -BinlogOutput ./ -NupkgOutput ./ -Release
263275

264276
- name: Validate package names
265277
if: ${{ env.VERSION_PROPERTY != '' }}

Directory.Build.props

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
1313
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
1414
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
15-
<NoWarn>$(NoWarn);Uno0001</NoWarn>
15+
<NoWarn>$(NoWarn);Uno0001</NoWarn>
16+
17+
<!-- See https://github.com/CommunityToolkit/Labs-Windows/pull/605#issuecomment-2498743676 -->
18+
<WarningsNotAsErrors>NU1901;NU1902;NU1903;NU1904</WarningsNotAsErrors>
1619
</PropertyGroup>
1720

1821
<Import Project="Windows.Toolkit.Common.props" />

components/MarkdownTextBlock/samples/MarkdownTextBlockCustomSample.xaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
<ColumnDefinition Width="*" />
2626
<ColumnDefinition Width="*" />
2727
</Grid.ColumnDefinitions>
28-
<controls:MarkdownTextBlock Grid.Column="0"
28+
<controls:MarkdownTextBlock x:Name="MarkdownTextBlock1"
29+
Grid.Column="0"
2930
Config="{x:Bind LiveMarkdownConfig, Mode=OneTime}"
3031
Text="{x:Bind MarkdownTextBox.Text, Mode=OneWay}" />
3132
<TextBox x:Name="MarkdownTextBox"
@@ -37,7 +38,8 @@
3738
FontSize="16"
3839
FontWeight="Bold"
3940
Text="Built-in Sample" />
40-
<controls:MarkdownTextBlock Grid.Row="3"
41+
<controls:MarkdownTextBlock x:Name="MarkdownTextBlock2"
42+
Grid.Row="3"
4143
Config="{x:Bind MarkdownConfig, Mode=OneTime}"
4244
Text="{x:Bind Text, Mode=OneTime}"
4345
UseAutoLinks="True"

components/MarkdownTextBlock/samples/MarkdownTextBlockCustomSample.xaml.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,5 +607,12 @@ public MarkdownTextBlockCustomSample()
607607
_liveConfig = new MarkdownConfig();
608608
_text = _markdown;
609609
MarkdownTextBox.Text = "# Hello World\n\n";
610+
MarkdownTextBlock1.OnLinkClicked += MarkdownTextBlock_OnLinkClicked;
611+
MarkdownTextBlock2.OnLinkClicked += MarkdownTextBlock_OnLinkClicked;
612+
}
613+
614+
private void MarkdownTextBlock_OnLinkClicked(object? sender, LinkClickedEventArgs e)
615+
{
616+
Debug.WriteLine($"Link Clicked: {e.Uri}");
610617
}
611618
}

components/MarkdownTextBlock/src/CommunityToolkit.WinUI.Controls.MarkdownTextBlock.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
</ItemGroup>
2222
<ItemGroup>
2323
<!--<PackageReference Include="ColorCode.Core" Version="2.0.14" />-->
24-
<PackageReference Include="HtmlAgilityPack" Version="1.11.48" />
25-
<PackageReference Include="Markdig" Version="0.31.0" />
26-
<PackageReference Include="Roman-Numerals" Version="2.0.0" />
24+
<PackageReference Include="HtmlAgilityPack" Version="1.11.71" />
25+
<PackageReference Include="Markdig" Version="0.38.0" />
26+
<PackageReference Include="Roman-Numerals" Version="2.0.1" />
2727
</ItemGroup>
2828
<ItemGroup Condition="'$(IsUwp)' == 'true'">
2929
<Using Include="Windows.UI" />

components/MarkdownTextBlock/src/HtmlWriter.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,21 @@ public static void WriteHtml(WinUIRenderer renderer, HtmlNodeCollection nodes)
3333
IAddChild hyperLink;
3434
if (node.ChildNodes.Any(n => n.Name != "#text"))
3535
{
36-
hyperLink = new MyHyperlinkButton(node, renderer.Config.BaseUrl);
36+
var myHyperlinkButton = new MyHyperlinkButton(node, renderer.Config.BaseUrl);
37+
myHyperlinkButton.ClickEvent += (sender, e) =>
38+
{
39+
renderer.MarkdownTextBlock.RaiseLinkClickedEvent(((HyperlinkButton)sender).NavigateUri);
40+
};
41+
hyperLink = myHyperlinkButton;
3742
}
3843
else
3944
{
40-
hyperLink = new MyHyperlink(node, renderer.Config.BaseUrl);
45+
var myHyperlink = new MyHyperlink(node, renderer.Config.BaseUrl);
46+
myHyperlink.ClickEvent += (sender, e) =>
47+
{
48+
renderer.MarkdownTextBlock.RaiseLinkClickedEvent(sender.NavigateUri);
49+
};
50+
hyperLink = myHyperlink;
4151
}
4252
renderer.Push(hyperLink);
4353
WriteHtml(renderer, node.ChildNodes);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace CommunityToolkit.Labs.WinUI.MarkdownTextBlock;
6+
7+
public class LinkClickedEventArgs : EventArgs
8+
{
9+
public Uri Uri { get; }
10+
11+
public LinkClickedEventArgs(Uri uri)
12+
{
13+
this.Uri = uri;
14+
}
15+
}

components/MarkdownTextBlock/src/MarkdownTextBlock.xaml.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ public partial class MarkdownTextBlock : Control
2020
private MyFlowDocument _document;
2121
private WinUIRenderer? _renderer;
2222

23+
public event EventHandler<LinkClickedEventArgs>? OnLinkClicked;
24+
25+
internal void RaiseLinkClickedEvent(Uri uri) => OnLinkClicked?.Invoke(this, new LinkClickedEventArgs(uri));
26+
2327
private static void OnConfigChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
2428
{
2529
if (d is MarkdownTextBlock self && e.NewValue != null)
@@ -95,7 +99,7 @@ private void Build()
9599
{
96100
if (_renderer == null)
97101
{
98-
_renderer = new WinUIRenderer(_document, Config);
102+
_renderer = new WinUIRenderer(_document, Config, this);
99103

100104
// Default block renderers
101105
_renderer.ObjectRenderers.Add(new CodeBlockRenderer());

components/MarkdownTextBlock/src/MarkdownThemes.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,15 @@ public sealed class MarkdownThemes : DependencyObject
4949

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

52+
public Thickness H1Margin { get; set; } = new(left: 0, top: 14, right: 0, bottom: 0);
53+
public Thickness H2Margin { get; set; } = new(left: 0, top: 14, right: 0, bottom: 0);
54+
public Thickness H3Margin { get; set; } = new(left: 0, top: 14, right: 0, bottom: 0);
55+
public Thickness H4Margin { get; set; } = new(left: 0, top: 14, right: 0, bottom: 0);
56+
public Thickness H5Margin { get; set; } = new(left: 0, top: 8, right: 0, bottom: 0);
57+
public Thickness H6Margin { get; set; } = new(left: 0, top: 8, right: 0, bottom: 0);
58+
5259
public Brush InlineCodeBackground { get; set; } = (Brush)Application.Current.Resources["ExpanderHeaderBackground"];
60+
public Brush InlineCodeForeground { get; set; } = (Brush)Application.Current.Resources["TextFillColorPrimaryBrush"];
5361

5462
public Brush InlineCodeBorderBrush { get; set; } = new SolidColorBrush(Colors.Gray);
5563

components/MarkdownTextBlock/src/Renderers/ObjectRenderers/Inlines/AutoLinkInlineRenderer.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ protected override void Write(WinUIRenderer renderer, AutolinkInline link)
2626
}
2727

2828
var autolink = new MyAutolinkInline(link);
29+
autolink.ClickEvent += (sender, e) =>
30+
{
31+
renderer.MarkdownTextBlock.RaiseLinkClickedEvent(sender.NavigateUri);
32+
};
2933

3034
renderer.Push(autolink);
3135

0 commit comments

Comments
 (0)