Skip to content

Commit

Permalink
Fix GH-154
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticmind committed Jan 27, 2022
1 parent 8ce47cc commit b8fc021
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[![](https://example.com/image.jpg)](https://www.example.com)
https://www.example.com
29 changes: 18 additions & 11 deletions src/ReverseMarkdown/Converters/A.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,30 @@ public override string Convert(HtmlNode node)

if (href.StartsWith("#") //anchor link
|| !Converter.Config.IsSchemeWhitelisted(scheme) //Not allowed scheme
|| isRemoveLinkWhenSameName //Same link - why bother with [](). Except when incorrectly escaped, i.e unescaped spaces - then bother with []()
|| string.IsNullOrEmpty(href) //We would otherwise print empty () here...
|| string.IsNullOrEmpty(name))
|| isRemoveLinkWhenSameName
|| string.IsNullOrEmpty(href)) //We would otherwise print empty () here...
{
return name;
}
else
{
var useHrefWithHttpWhenNameHasNoScheme = Converter.Config.SmartHrefHandling &&
(scheme.Equals("http", StringComparison.OrdinalIgnoreCase) || scheme.Equals("https", StringComparison.OrdinalIgnoreCase))
&& string.Equals(href, $"{scheme}://{name}", StringComparison.OrdinalIgnoreCase);

// if (!string.IsNullOrEmpty(href) && string.IsNullOrEmpty(name))
// {
// name = href;
// }

var useHrefWithHttpWhenNameHasNoScheme = Converter.Config.SmartHrefHandling &&
(scheme.Equals("http", StringComparison.OrdinalIgnoreCase) || scheme.Equals("https", StringComparison.OrdinalIgnoreCase))
&& string.Equals(href, $"{scheme}://{name}", StringComparison.OrdinalIgnoreCase);

// if the anchor tag contains a single child image node don't escape the link text
var linkText = hasSingleChildImgNode ? name : StringUtils.EscapeLinkText(name);
// if the anchor tag contains a single child image node don't escape the link text
var linkText = hasSingleChildImgNode ? name : StringUtils.EscapeLinkText(name);

return useHrefWithHttpWhenNameHasNoScheme ? href : $"[{linkText}]({href}{title})";
if (string.IsNullOrEmpty(linkText))
{
return href;
}

return useHrefWithHttpWhenNameHasNoScheme ? href : $"[{linkText}]({href}{title})";
}
}
}
5 changes: 5 additions & 0 deletions src/ReverseMarkdown/Converters/Img.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ public Img(Converter converter) : base(converter)

public override string Convert(HtmlNode node)
{
if (node.ParentNode.Name == "a")
{
return string.Empty;
}

var alt = node.GetAttributeValue("alt", string.Empty);
var src = node.GetAttributeValue("src", string.Empty);

Expand Down

0 comments on commit b8fc021

Please sign in to comment.