Skip to content

Commit

Permalink
Make links clickable in Markdown Preview for Docs
Browse files Browse the repository at this point in the history
Remove extra blank entry for empty text after last sample
Fix template text for Markdown display
  • Loading branch information
michael-hawker committed Jul 20, 2022
1 parent 34d2431 commit df5f789
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,15 @@ namespace CommunityToolkit.Labs.Shared.Renderers;
/// </summary>
public partial class MarkdownTextBlock : ToolkitMTB
{
#if HAS_UNO
//// Polyfill dummy for event callback
#pragma warning disable CS0067 // Unused on purpose for polyfill
public event EventHandler<LinkClickedEventArgs>? LinkClicked;
#pragma warning restore CS0067 // Unused on purpose for polyfill
#endif
}

#if HAS_UNO
//// Polyfill dummy for event callback
public class LinkClickedEventArgs : EventArgs { }
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<DataTemplate x:Key="DocumentTemplate"
x:DataType="x:String">
<renderer:MarkdownTextBlock Background="Transparent"
LinkClicked="MarkdownTextBlock_LinkClicked"
Text="{Binding}"
TextWrapping="WrapWholeWords" />
</DataTemplate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
using CommunityToolkit.Labs.Core.SourceGenerators;
using CommunityToolkit.Labs.Core.SourceGenerators.Metadata;
using Windows.Storage;
using Windows.System;

#if !HAS_UNO
#if !WINAPPSDK
using Microsoft.Toolkit.Uwp.UI.Controls;
#else
using CommunityToolkit.WinUI.UI.Controls;
#endif
#endif

namespace CommunityToolkit.Labs.Shared.Renderers;

Expand Down Expand Up @@ -113,8 +122,12 @@ private async Task LoadData()
index = match.Index + match.Length;
}

// Put rest of text at end
DocsAndSamples.Add(doctext.Substring(index));
var rest = doctext.Substring(index).Trim();
// Put rest of text at end (if any)
if (rest.Length > 0)
{
DocsAndSamples.Add(rest);
}
}
}

Expand Down Expand Up @@ -174,4 +187,30 @@ private static async Task<string> GetDocumentationFileContents(ToolkitFrontMatte
return $"Exception Encountered Loading file '{fileUri}':\n{e.Message}\n{e.StackTrace}";
}
}


#if HAS_UNO
private void MarkdownTextBlock_LinkClicked(object sender, LinkClickedEventArgs e)
{
// No-op - TODO: See https://github.com/CommunityToolkit/Labs-Windows/issues/151
}
#elif !HAS_UNO
private async void MarkdownTextBlock_LinkClicked(object sender, LinkClickedEventArgs e)
{
if (!Uri.IsWellFormedUriString(e.Link, UriKind.Absolute))
{
await new ContentDialog
{
Title = "Windows Community Toolkit Labs Sample App",
Content = $"Link {e.Link} was malformed.",
CloseButtonText = "Close",
XamlRoot = XamlRoot // TODO: For UWP this is only on 1903+
}.ShowAsync();
}
else
{
await Launcher.LaunchUriAsync(new Uri(e.Link));
}
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ subcategory: Layout
# ProjectTemplate

For more information about this experiment see:

- Discussion: TODO: PASTE LINK HERE
- Issue: TODO: PASTE LINK HERE

Expand Down

0 comments on commit df5f789

Please sign in to comment.