Skip to content

Commit 8ea040f

Browse files
author
Juan Osorio
committed
Merge branch 'main' into user/juosori/temp_fenced_code_block
2 parents 05709d0 + 6dafb91 commit 8ea040f

16 files changed

+152
-49
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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
1+
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
22
<Page x:Class="MarkdownTextBlockExperiment.Samples.MarkdownTextBlockCustomSample"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
@@ -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
</Grid>

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/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
@@ -42,6 +42,10 @@ public string Text
4242
set => SetValue(TextProperty, value);
4343
}
4444

45+
public event EventHandler<LinkClickedEventArgs>? OnLinkClicked;
46+
47+
internal void RaiseLinkClickedEvent(Uri uri) => OnLinkClicked?.Invoke(this, new LinkClickedEventArgs(uri));
48+
4549
private static void OnConfigChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
4650
{
4751
if (d is MarkdownTextBlock self && e.NewValue != null)
@@ -110,7 +114,7 @@ private void Build()
110114
{
111115
if (_renderer == null)
112116
{
113-
_renderer = new WinUIRenderer(_document, Config);
117+
_renderer = new WinUIRenderer(_document, Config, this);
114118
}
115119
_pipeline.Setup(_renderer);
116120
ApplyText(false);

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(0);
53+
public Thickness H2Margin { get; set; } = new(0);
54+
public Thickness H3Margin { get; set; } = new(0);
55+
public Thickness H4Margin { get; set; } = new(0);
56+
public Thickness H5Margin { get; set; } = new(0);
57+
public Thickness H6Margin { get; set; } = new(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

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,20 @@ protected override void Write(WinUIRenderer renderer, LinkInline link)
3030
{
3131
if (link.FirstChild is LinkInline linkInlineChild && linkInlineChild.IsImage)
3232
{
33-
renderer.Push(new MyHyperlinkButton(link, renderer.Config.BaseUrl));
33+
var myHyperlinkButton = new MyHyperlinkButton(link, renderer.Config.BaseUrl);
34+
myHyperlinkButton.ClickEvent += (sender, e) =>
35+
{
36+
renderer.MarkdownTextBlock.RaiseLinkClickedEvent(((HyperlinkButton)sender).NavigateUri);
37+
};
38+
renderer.Push(myHyperlinkButton);
3439
}
3540
else
3641
{
3742
var hyperlink = new MyHyperlink(link, renderer.Config.BaseUrl);
43+
hyperlink.ClickEvent += (sender, e) =>
44+
{
45+
renderer.MarkdownTextBlock.RaiseLinkClickedEvent(sender.NavigateUri);
46+
};
3847

3948
renderer.Push(hyperlink);
4049
}

0 commit comments

Comments
 (0)