Skip to content

Commit 09f4713

Browse files
Make links clickable in Markdown Preview for Docs
Remove extra blank entry for empty text after last sample Fix template text for Markdown display
1 parent 2c96e70 commit 09f4713

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

common/CommunityToolkit.Labs.Shared/Renderers/Markdown/MarkdownTextBlock.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,15 @@ namespace CommunityToolkit.Labs.Shared.Renderers;
2323
/// </summary>
2424
public partial class MarkdownTextBlock : ToolkitMTB
2525
{
26+
#if HAS_UNO
27+
//// Polyfill dummy for event callback
28+
#pragma warning disable CS0067 // Unused on purpose for polyfill
29+
public event EventHandler<LinkClickedEventArgs>? LinkClicked;
30+
#pragma warning restore CS0067 // Unused on purpose for polyfill
31+
#endif
2632
}
33+
34+
#if HAS_UNO
35+
//// Polyfill dummy for event callback
36+
public class LinkClickedEventArgs : EventArgs { }
37+
#endif

common/CommunityToolkit.Labs.Shared/Renderers/ToolkitDocumentationRenderer.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<DataTemplate x:Key="DocumentTemplate"
1818
x:DataType="x:String">
1919
<renderer:MarkdownTextBlock Background="Transparent"
20+
LinkClicked="MarkdownTextBlock_LinkClicked"
2021
Text="{Binding}"
2122
TextWrapping="WrapWholeWords" />
2223
</DataTemplate>

common/CommunityToolkit.Labs.Shared/Renderers/ToolkitDocumentationRenderer.xaml.cs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
using CommunityToolkit.Labs.Core.SourceGenerators;
66
using CommunityToolkit.Labs.Core.SourceGenerators.Metadata;
77
using Windows.Storage;
8+
using Windows.System;
9+
10+
#if !HAS_UNO
11+
#if !WINAPPSDK
12+
using Microsoft.Toolkit.Uwp.UI.Controls;
13+
#else
14+
using CommunityToolkit.WinUI.UI.Controls;
15+
#endif
16+
#endif
817

918
namespace CommunityToolkit.Labs.Shared.Renderers;
1019

@@ -113,8 +122,12 @@ private async Task LoadData()
113122
index = match.Index + match.Length;
114123
}
115124

116-
// Put rest of text at end
117-
DocsAndSamples.Add(doctext.Substring(index));
125+
var rest = doctext.Substring(index).Trim();
126+
// Put rest of text at end (if any)
127+
if (rest.Length > 0)
128+
{
129+
DocsAndSamples.Add(rest);
130+
}
118131
}
119132
}
120133

@@ -174,4 +187,30 @@ private static async Task<string> GetDocumentationFileContents(ToolkitFrontMatte
174187
return $"Exception Encountered Loading file '{fileUri}':\n{e.Message}\n{e.StackTrace}";
175188
}
176189
}
190+
191+
192+
#if HAS_UNO
193+
private void MarkdownTextBlock_LinkClicked(object sender, LinkClickedEventArgs e)
194+
{
195+
// No-op - TODO: See https://github.com/CommunityToolkit/Labs-Windows/issues/151
196+
}
197+
#elif !HAS_UNO
198+
private async void MarkdownTextBlock_LinkClicked(object sender, LinkClickedEventArgs e)
199+
{
200+
if (!Uri.IsWellFormedUriString(e.Link, UriKind.Absolute))
201+
{
202+
await new ContentDialog
203+
{
204+
Title = "Windows Community Toolkit Labs Sample App",
205+
Content = $"Link {e.Link} was malformed.",
206+
CloseButtonText = "Close",
207+
XamlRoot = XamlRoot // TODO: For UWP this is only on 1903+
208+
}.ShowAsync();
209+
}
210+
else
211+
{
212+
await Launcher.LaunchUriAsync(new Uri(e.Link));
213+
}
214+
}
215+
#endif
177216
}

template/lab/samples/ProjectTemplate.Samples/ProjectTemplate.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ subcategory: Layout
1818
# ProjectTemplate
1919

2020
For more information about this experiment see:
21+
2122
- Discussion: TODO: PASTE LINK HERE
2223
- Issue: TODO: PASTE LINK HERE
2324

0 commit comments

Comments
 (0)