Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix link edge cases #67

Merged
merged 2 commits into from
Jun 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Source/MMSpanParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,7 @@ - (MMElement *)_parseInlineLinkWithScanner:(MMScanner *)scanner
if (scanner.nextCharacter != '(')
return nil;
[scanner advance];
[scanner skipWhitespace];

NSUInteger urlLocation = scanner.location;
NSUInteger urlEnd = urlLocation;
Expand Down Expand Up @@ -1017,6 +1018,13 @@ - (MMElement *)_parseInlineLinkWithScanner:(MMScanner *)scanner
{
if (level != 1)
return nil;

[scanner skipWhitespace];
if (scanner.nextCharacter == ')')
{
[scanner advance];
level -= 1;
}
break;
}
urlEnd = scanner.location;
Expand All @@ -1029,9 +1037,6 @@ - (MMElement *)_parseInlineLinkWithScanner:(MMScanner *)scanner
// If the level is still 1, then we hit a space.
if (level == 1)
{
// skip the whitespace
[scanner skipCharactersFromSet:NSCharacterSet.whitespaceCharacterSet];

// make sure there's a "
if (scanner.nextCharacter != '"')
return nil;
Expand Down Expand Up @@ -1096,6 +1101,8 @@ - (MMElement *)_parseReferenceLinkWithScanner:(MMScanner *)scanner

// Look for the second []
NSArray *idRanges = [self _parseLinkTextBodyWithScanner:scanner];
if (!idRanges)
return nil;
if (!idRanges.count)
{
idRanges = element.innerRanges;
Expand Down
10 changes: 10 additions & 0 deletions Tests/MMLinkTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,16 @@ - (void)testInlineLinkWithImage
);
}

- (void)testInlineLinkWithPadding
{
MMAssertMarkdownEqualsHTML(@"[test]( http://www.test.com )", @"<p><a href=\"http://www.test.com\">test</a></p>");
}

- (void)testInlineLinkInsideBrackets
{
MMAssertMarkdownEqualsHTML(@"[[test](http://www.test.com)]", @"<p>[<a href=\"http://www.test.com\">test</a>]</p>");
}


#pragma mark - Reference Link Tests

Expand Down