Skip to content

Commit

Permalink
Merge pull request xoofx#195 from leotsarev/remove-mailto
Browse files Browse the repository at this point in the history
AutoLinkParser should to remove mailto: in outputted text
  • Loading branch information
xoofx authored Jan 10, 2018
2 parents 6dff16a + 0f7e3b8 commit c29b7d2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/Markdig.Tests/Specs/AutoLinks.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ And a plain www.google.com
.
<p>This is a <a href="http://www.google.com">http://www.google.com</a> URL and <a href="https://www.google.com">https://www.google.com</a>
This is a <a href="ftp://test.com">ftp://test.com</a>
And a <a href="mailto:[email protected]">mailto:[email protected]</a>
And a <a href="mailto:[email protected]">[email protected]</a>
And a plain <a href="http://www.google.com">www.google.com</a></p>
````````````````````````````````

Expand Down
26 changes: 13 additions & 13 deletions src/Markdig.Tests/Specs/Specs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20340,7 +20340,7 @@ public void ExtensionsHeadingAutoIdentifiers_Example010()
public partial class TestExtensionsHeadingAutoIdentifiers
{
[Test]
public void Example011()
public void ExtensionsHeadingAutoIdentifiers_Example011()
{
// Example 11
// Section: Extensions Heading Auto Identifiers
Expand Down Expand Up @@ -20702,7 +20702,7 @@ public void ExtensionsYAMLfrontmatterdiscard_Example006()
public partial class TestExtensionsYAMLfrontmatterdiscard
{
[Test]
public void Example007()
public void ExtensionsYAMLfrontmatterdiscard_Example007()
{
// Example 7
// Section: Extensions YAML frontmatter discard
Expand All @@ -20728,7 +20728,7 @@ public void Example007()
public partial class TestExtensionsYAMLfrontmatterdiscard
{
[Test]
public void ExtensionsYAMLfrontmatterdiscard_Example007()
public void ExtensionsYAMLfrontmatterdiscard_Example008()
{
// Example 8
// Section: Extensions YAML frontmatter discard
Expand All @@ -20751,7 +20751,7 @@ public void ExtensionsYAMLfrontmatterdiscard_Example007()
public partial class TestExtensionsYAMLfrontmatterdiscard
{
[Test]
public void ExtensionsYAMLfrontmatterdiscard_Example008()
public void ExtensionsYAMLfrontmatterdiscard_Example009()
{
// Example 9
// Section: Extensions YAML frontmatter discard
Expand Down Expand Up @@ -20799,11 +20799,11 @@ public void ExtensionsAutoLinks_Example001()
// Should be rendered as:
// <p>This is a <a href="http://www.google.com">http://www.google.com</a> URL and <a href="https://www.google.com">https://www.google.com</a>
// This is a <a href="ftp://test.com">ftp://test.com</a>
// And a <a href="mailto:[email protected]">mailto:[email protected]</a>
// And a <a href="mailto:[email protected]">[email protected]</a>
// And a plain <a href="http://www.google.com">www.google.com</a></p>

Console.WriteLine("Example {0}" + Environment.NewLine + "Section: {0}" + Environment.NewLine, 1, "Extensions AutoLinks");
TestParser.TestSpec("This is a http://www.google.com URL and https://www.google.com\nThis is a ftp://test.com\nAnd a mailto:[email protected]\nAnd a plain www.google.com", "<p>This is a <a href=\"http://www.google.com\">http://www.google.com</a> URL and <a href=\"https://www.google.com\">https://www.google.com</a>\nThis is a <a href=\"ftp://test.com\">ftp://test.com</a>\nAnd a <a href=\"mailto:[email protected]\">mailto:[email protected]</a>\nAnd a plain <a href=\"http://www.google.com\">www.google.com</a></p>", "autolinks|advanced");
TestParser.TestSpec("This is a http://www.google.com URL and https://www.google.com\nThis is a ftp://test.com\nAnd a mailto:[email protected]\nAnd a plain www.google.com", "<p>This is a <a href=\"http://www.google.com\">http://www.google.com</a> URL and <a href=\"https://www.google.com\">https://www.google.com</a>\nThis is a <a href=\"ftp://test.com\">ftp://test.com</a>\nAnd a <a href=\"mailto:[email protected]\">[email protected]</a>\nAnd a plain <a href=\"http://www.google.com\">www.google.com</a></p>", "autolinks|advanced");
}
}
// But incomplete links will not be matched:
Expand Down Expand Up @@ -20939,7 +20939,7 @@ public void ExtensionsAutoLinks_Example007()
public partial class TestExtensionsAutoLinksGFMSupport
{
[Test]
public void Example008()
public void ExtensionsAutoLinksGFMSupport_Example008()
{
// Example 8
// Section: Extensions AutoLinks GFM Support
Expand All @@ -20958,7 +20958,7 @@ public void Example008()
public partial class TestExtensionsAutoLinksGFMSupport
{
[Test]
public void Example009()
public void ExtensionsAutoLinksGFMSupport_Example009()
{
// Example 9
// Section: Extensions AutoLinks GFM Support
Expand All @@ -20977,7 +20977,7 @@ public void Example009()
public partial class TestExtensionsAutoLinksGFMSupport
{
[Test]
public void Example010()
public void ExtensionsAutoLinksGFMSupport_Example010()
{
// Example 10
// Section: Extensions AutoLinks GFM Support
Expand All @@ -20999,7 +20999,7 @@ public void Example010()
public partial class TestExtensionsAutoLinksGFMSupport
{
[Test]
public void Example011()
public void ExtensionsAutoLinksGFMSupport_Example011()
{
// Example 11
// Section: Extensions AutoLinks GFM Support
Expand All @@ -21021,7 +21021,7 @@ public void Example011()
public partial class TestExtensionsAutoLinksGFMSupport
{
[Test]
public void Example012()
public void ExtensionsAutoLinksGFMSupport_Example012()
{
// Example 12
// Section: Extensions AutoLinks GFM Support
Expand All @@ -21043,7 +21043,7 @@ public void Example012()
public partial class TestExtensionsAutoLinksGFMSupport
{
[Test]
public void Example013()
public void ExtensionsAutoLinksGFMSupport_Example013()
{
// Example 13
// Section: Extensions AutoLinks GFM Support
Expand All @@ -21062,7 +21062,7 @@ public void Example013()
public partial class TestExtensionsAutoLinksGFMSupport
{
[Test]
public void Example014()
public void ExtensionsAutoLinksGFMSupport_Example014()
{
// Example 14
// Section: Extensions AutoLinks GFM Support
Expand Down
2 changes: 1 addition & 1 deletion src/Markdig.Tests/TestNormalize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ public void AutoLinks()
AssertNormalizeNoTrim("Hello from http://example.com/foo", "Hello from [http://example.com/foo](http://example.com/foo)", new NormalizeOptions() { ExpandAutoLinks = true, });
AssertNormalizeNoTrim("Hello from www.example.com/foo", "Hello from [www.example.com/foo](http://www.example.com/foo)", new NormalizeOptions() { ExpandAutoLinks = true, });
AssertNormalizeNoTrim("Hello from ftp://example.com", "Hello from [ftp://example.com](ftp://example.com)", new NormalizeOptions() { ExpandAutoLinks = true, });
AssertNormalizeNoTrim("Hello from mailto:[email protected]", "Hello from [mailto:[email protected]](mailto:[email protected])", new NormalizeOptions() { ExpandAutoLinks = true, });
AssertNormalizeNoTrim("Hello from mailto:[email protected]", "Hello from [[email protected]](mailto:[email protected])", new NormalizeOptions() { ExpandAutoLinks = true, });

AssertNormalizeNoTrim("Hello from http://example.com/foo", "Hello from http://example.com/foo", new NormalizeOptions() { ExpandAutoLinks = false, });
AssertNormalizeNoTrim("Hello from www.example.com/foo", "Hello from http://www.example.com/foo", new NormalizeOptions() { ExpandAutoLinks = false, });
Expand Down
5 changes: 4 additions & 1 deletion src/Markdig/Extensions/AutoLinks/AutoLinkParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,17 @@ public override bool Match(InlineProcessor processor, ref StringSlice slice)
IsClosed = true,
IsAutoLink = true,
};

var skipFromBeginning = c == 'm' ? 7 : 0; // For mailto: skip "mailto:" for content

inline.Span.End = inline.Span.Start + link.Length - 1;
inline.UrlSpan = inline.Span;
inline.AppendChild(new LiteralInline()
{
Span = inline.Span,
Line = line,
Column = column,
Content = new StringSlice(slice.Text, startPosition, startPosition + link.Length - 1),
Content = new StringSlice(slice.Text, startPosition + skipFromBeginning, startPosition + link.Length - 1),
IsClosed = true
});
processor.Inline = inline;
Expand Down

0 comments on commit c29b7d2

Please sign in to comment.