Browse Source

Dont normalize external links/images

pull/570/head
Halil ibrahim Kalkan 8 years ago
parent
commit
03a79965a7
  1. 13
      modules/docs/src/Volo.Docs.Web/Areas/Documents/Helpers/TagHelpers/TreeTagHelper.cs
  2. 15
      modules/docs/src/Volo.Docs.Web/Formatting/MarkdownDocumentConverter.cs
  3. 7
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/HtmlNormalizer.cs
  4. 18
      modules/docs/src/Volo.Docs.Web/Utils/UrlHelper.cs

13
modules/docs/src/Volo.Docs.Web/Areas/Documents/Helpers/TagHelpers/TreeTagHelper.cs

@ -3,6 +3,7 @@ using System.Linq;
using System.Text;
using Microsoft.AspNetCore.Razor.TagHelpers;
using Volo.Docs.Documents;
using Volo.Docs.Utils;
namespace Volo.Docs.Areas.Documents.Helpers.TagHelpers
{
@ -116,7 +117,7 @@ namespace Volo.Docs.Areas.Documents.Helpers.TagHelpers
private string NormalizePath(string path, bool hasChildItems)
{
if (IsExternalLink(path))
if (UrlHelper.IsExternalLink(path))
{
return path;
}
@ -131,16 +132,6 @@ namespace Volo.Docs.Areas.Documents.Helpers.TagHelpers
return "/documents/" + ProjectName + "/" + Version + "/" + pathWithoutFileExtension;
}
protected virtual bool IsExternalLink(string path)
{
if (path.IsNullOrEmpty())
{
return false;
}
return path.StartsWith("http") || path.StartsWith("https");
}
private string RemoveFileExtensionFromPath(string path)
{
if (path == null)

15
modules/docs/src/Volo.Docs.Web/Formatting/MarkdownDocumentConverter.cs

@ -1,8 +1,9 @@
using System;
using CommonMark;
using System;
using System.Text;
using System.Text.RegularExpressions;
using CommonMark;
using Volo.Abp.DependencyInjection;
using Volo.Docs.Utils;
namespace Volo.Docs.Formatting
{
@ -31,8 +32,15 @@ namespace Volo.Docs.Formatting
var normalized = Regex.Replace(content, MarkdownLinkRegExp, delegate (Match match)
{
var link = match.Groups[2].Value;
if (UrlHelper.IsExternalLink(link))
{
return match.Value;
}
var displayText = match.Groups[1].Value;
var documentName = RemoveFileExtension(match.Groups[2].Value);
var documentName = RemoveFileExtension(link);
var documentLocalDirectoryNormalized = documentLocalDirectory.TrimStart('/').TrimEnd('/');
if (!string.IsNullOrWhiteSpace(documentLocalDirectoryNormalized))
{
@ -84,6 +92,7 @@ namespace Volo.Docs.Formatting
return documentName.Left(documentName.Length - Type.Length - 1);
}
//TODO: Merge with UrlHelper.IsExternalLink
private static bool IsRemoteUrl(string url)
{
if (url == null)

7
modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/HtmlNormalizer.cs

@ -1,5 +1,6 @@
using System;
using System.Text.RegularExpressions;
using Volo.Docs.Utils;
namespace Volo.Docs.Pages.Documents.Project
{
@ -14,9 +15,15 @@ namespace Volo.Docs.Pages.Documents.Project
content = Regex.Replace(content, @"(<img\s+[^>]*)src=""([^""]*)""([^>]*>)", delegate (Match match)
{
if (UrlHelper.IsExternalLink(match.Groups[2].Value))
{
return match.Value;
}
var newImageSource = documentRawRootUrl.EnsureEndsWith('/') +
(localDirectory.IsNullOrEmpty() ? "" : localDirectory.TrimStart('/').EnsureEndsWith('/')) +
match.Groups[2].Value.TrimStart('/');
return match.Groups[1] + " src=\"" + newImageSource + "\" " + match.Groups[3];
}, RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.Multiline);

18
modules/docs/src/Volo.Docs.Web/Utils/UrlHelper.cs

@ -0,0 +1,18 @@
using System;
namespace Volo.Docs.Utils
{
public static class UrlHelper
{
public static bool IsExternalLink(string path)
{
if (path.IsNullOrEmpty())
{
return false;
}
return path.StartsWith("http://", StringComparison.OrdinalIgnoreCase) ||
path.StartsWith("https://", StringComparison.OrdinalIgnoreCase);
}
}
}
Loading…
Cancel
Save