Skip to content

Commit

Permalink
Merge remote-tracking branch 'mdiep/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
albertbori committed Dec 6, 2016
2 parents b198edc + f4016ad commit c9d594d
Show file tree
Hide file tree
Showing 2 changed files with 203 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Source/MMParser.m
Expand Up @@ -462,6 +462,20 @@ - (MMElement *)_parseBlockquoteWithScanner:(MMScanner *)scanner
[scanner advance];
[scanner skipCharactersFromSet:whitespaceSet max:1];
}
else
{
//
// If the following line is a list item
// then break the blockquote parsering.
//
[scanner beginTransaction];
[scanner skipIndentationUpTo:2];
BOOL hasListMarker = [self _parseListMarkerWithScanner:scanner listType:MMListTypeBulleted]
|| [self _parseListMarkerWithScanner:scanner listType:MMListTypeNumbered];
[scanner commitTransaction:NO];
if (hasListMarker)
break;
}

[element addInnerRange:scanner.currentRange];

Expand Down Expand Up @@ -851,6 +865,32 @@ - (MMElement *)_parseListItemWithScanner:(MMScanner *)scanner listType:(MMListTy
{
[self _addTextLineToElement:element withScanner:scanner];
}

[scanner beginTransaction];
[scanner skipIndentationUpTo:4];
if (scanner.nextCharacter == '>')
{
//
// If next line is start with blockquote mark
// then break current list parsering.
//
// for example:
//
// > 123
// + abc
//
// "+ abs" should not consider as part of blockquote
//
// > 234
// 567
//
// "567" is part of the blockquote
//
[scanner commitTransaction:NO];
break;
}
[scanner commitTransaction:NO];

}

element.range = NSMakeRange(scanner.startLocation, scanner.location-scanner.startLocation);
Expand Down
163 changes: 163 additions & 0 deletions Tests/MMListTests.m
Expand Up @@ -379,6 +379,16 @@ - (void)testList_withLeadingSpace
MMAssertMarkdownEqualsHTML(@" - One\n - Two", @"<ul><li>One</li><li>Two</li></ul>");
}

- (void)testList_withBold
{
MMAssertMarkdownEqualsHTML(@" - One **Bold**\n - Two", @"<ul><li>One <strong>Bold</strong></li><li>Two</li></ul>");
}

- (void)testList_withCode
{
MMAssertMarkdownEqualsHTML(@" - One `Code`\n - Two", @"<ul><li>One <code>Code</code></li><li>Two</li></ul>");
}

- (void)testListFollowingAnotherList
{
NSString *markdown =
Expand Down Expand Up @@ -417,5 +427,158 @@ - (void)testListWith2SpaceIndentation
MMAssertMarkdownEqualsHTML(markdown, HTML);
}

- (void)testAlternateListAndQuoteWithDoubleNewlines
{
NSString *markdown =
@"+ abc\n\n"
@"> 123\n\n"
@"+ def\n\n"
@"> 456\n\n";

NSString *HTML =
@"<ul>\n"
@"<li>abc</li>\n"
@"</ul>\n"
@"<blockquote>\n"
@"<p>123</p>\n"
@"</blockquote>\n"
@"<ul>\n"
@"<li>def</li>\n"
@"</ul>\n"
@"<blockquote>\n"
@"<p>456</p>\n"
@"</blockquote>\n";

MMAssertMarkdownEqualsHTML(markdown, HTML);
}

- (void)testAlternateListAndQuote
{
NSString *markdown =
@"+ abc\n"
@"> 123\n"
@"+ def\n"
@"> 456\n";

NSString *HTML =
@"<ul>\n"
@"<li>abc</li>\n"
@"</ul>\n"
@"<blockquote>\n"
@"<p>123</p>\n"
@"</blockquote>\n"
@"<ul>\n"
@"<li>def</li>\n"
@"</ul>\n"
@"<blockquote>\n"
@"<p>456</p>\n"
@"</blockquote>\n";

MMAssertMarkdownEqualsHTML(markdown, HTML);
}


- (void)testAlternateListAndQuoteWith3SpaceBeforeQuote
{
NSString *markdown =
@"+ abc\n"
@" > 123\n"
@"+ def\n"
@"> 456\n";

NSString *HTML =
@"<ul>\n"
@"<li>abc</li>\n"
@"</ul>\n"
@"<blockquote>\n"
@"<p>123</p>\n"
@"</blockquote>\n"
@"<ul>\n"
@"<li>def</li>\n"
@"</ul>\n"
@"<blockquote>\n"
@"<p>456</p>\n"
@"</blockquote>\n";

MMAssertMarkdownEqualsHTML(markdown, HTML);
}


- (void)testAlternateListAndQuoteWith4SpaceBeforeQuote
{
NSString *markdown =
@"+ abc\n"
@" > 123\n"
@"+ def\n"
@"> 456\n";

NSString *HTML =
@"<ul>\n"
@"<li>abc</li>\n"
@"</ul>\n"
@"<pre><code>&gt; 123\n</code></pre>\n"
@"<ul>\n"
@"<li>def</li>\n"
@"</ul>\n"
@"<blockquote>\n"
@"<p>456</p>\n"
@"</blockquote>\n";

MMAssertMarkdownEqualsHTML(markdown, HTML);
}


- (void)testAlternateListAndQuoteWith3SpaceBeforeListItem
{
NSString *markdown =
@"+ abc\n"
@"> 123\n"
@" + def\n"
@"> 456\n";

NSString *HTML =
@"<ul>\n"
@"<li>abc</li>\n"
@"</ul>\n"
@"<blockquote>\n"
@"<p>123</p>\n"
@"</blockquote>\n"
@"<ul>\n"
@"<li>def</li>\n"
@"</ul>\n"
@"<blockquote>\n"
@"<p>456</p>\n"
@"</blockquote>\n";

MMAssertMarkdownEqualsHTML(markdown, HTML);
}


- (void)testAlternateListAndQuoteWith4SpaceBeforeListItem
{
NSString *markdown =
@"+ abc\n"
@"> 123\n"
@" + def\n"
@"> 456\n";

NSString *HTML =
@"<ul>\n"
@"<li>abc</li>\n"
@"</ul>\n"
@"<blockquote>\n"
@"<p>123</p>\n"
@"</blockquote>\n"
@"<ul>\n"
@"<li>def</li>\n"
@"</ul>\n"
@"<blockquote>\n"
@"<p>456</p>\n"
@"</blockquote>\n";

MMAssertMarkdownEqualsHTML(markdown, HTML);
}



@end

0 comments on commit c9d594d

Please sign in to comment.