Skip to content

Commit

Permalink
Fixes #1607 #1594
Browse files Browse the repository at this point in the history
Fixes #1607 #1594
  • Loading branch information
avknaidu committed Nov 20, 2017
1 parent 3201148 commit 7aad125
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,40 @@ results in:
There are other methods of generating links that aren't appropriate for discussion-board style comments. See the [Markdown Syntax](http://daringfireball.net/projects/markdown/syntax#link) if you're interested in more info.

 

Relative links are also supported

>\[Relative Link\]\(/Assets/Photos/Photos.json\)
results in:

>[Relative Link](/Assets/Photos/Photos.json)
 

>\[Relative Link 2\]\(../Photos/Photos.json\)
results in:

>[Relative Link 2](../Photos/Photos.json)
**Note:** Relative Links has to be Manually Handled in `LinkClicked` Event.

*****

# Email Links

Emails can be used as Masked Links or Direct email links.

>[Email\]\(`email@email.com`)
will be rendered to [Email](email@email.com)

>`email@email.com`
will be rendered to email@email.com

*****

# IMAGES
Expand All @@ -287,6 +321,14 @@ which renders in:

![Toolkit logo](https://raw.githubusercontent.com/Microsoft/UWPCommunityToolkit/master/Microsoft.Toolkit.Uwp.SampleApp/Assets/ToolkitLogo.png)

Rendering Local Images is supported.

>\!\[Local Image](/Assets/Helpers.png)
renders in

![Local Image](/Assets/Helpers.png)

*****

# BLOCK QUOTES
Expand Down Expand Up @@ -317,6 +359,12 @@ And finally some unquoted text.

*****

# EMOJIS

You can use nearly all emojis from this [list](https://gist.github.com/rxaviers/7360908). Text like `:smile:` will display :smile: emoji.

*****

# MISCELLANEOUS

### Tables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Windows.System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Popups;

namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
{
Expand Down Expand Up @@ -69,7 +70,14 @@ private void SetInitalText(string text)

private async void MarkdownText_LinkClicked(object sender, UI.Controls.LinkClickedEventArgs e)
{
await Launcher.LaunchUriAsync(new Uri(e.Link));
if (e.Link.StartsWith("../") || e.Link.StartsWith("/"))
{
await new MessageDialog("Masked relative links needs to be manually handled.").ShowAsync();
}
else
{
await Launcher.LaunchUriAsync(new Uri(e.Link));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ internal static Common.InlineParseResult Parse(string markdown, int start, int e
}

string url = TextRunInline.ResolveEscapeSequences(markdown, urlStart, pos);
url = url.StartsWith("/") ? string.Format("ms-appx://{0}", url) : url;

// We found something!
var result = new ImageInline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System;
using System.Collections.Generic;
using Microsoft.Toolkit.Uwp.UI.Controls.Markdown.Helpers;
using System.Text.RegularExpressions;

namespace Microsoft.Toolkit.Uwp.UI.Controls.Markdown.Parse
{
Expand Down Expand Up @@ -193,9 +194,16 @@ internal static Common.InlineParseResult Parse(string markdown, int start, int m
}

// Check the URL is okay.
if (!IsUrlValid(url))
if (!IsUrlEmail(url))
{
return null;
if (!IsUrlValid(url))
{
return null;
}
}
else
{
tooltip = url = string.Format("mailto:{0}",url);
}

// We found a regular stand-alone link.
Expand Down Expand Up @@ -264,6 +272,21 @@ public void ResolveReference(MarkdownDocument document)
ReferenceId = null;
}

/// <summary>
/// Checks if the given URL is an Email.
/// </summary>
/// <param name="url"> The URL to check. </param>
/// <returns> <c>true</c> if the URL is valid; <c>false</c> otherwise. </returns>
private static bool IsUrlEmail(string url)
{
if (Regex.IsMatch(url, @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,})+)$"))
{
return true;
}

return false;
}

/// <summary>
/// Checks if the given URL is allowed in a markdown link.
/// </summary>
Expand All @@ -272,7 +295,7 @@ public void ResolveReference(MarkdownDocument document)
private static bool IsUrlValid(string url)
{
// URLs can be relative.
if (url.StartsWith("/") || url.StartsWith("#"))
if (url.StartsWith("/") || url.StartsWith("#") || url.StartsWith("../"))
{
return true;
}
Expand Down

0 comments on commit 7aad125

Please sign in to comment.