Skip to content

Commit

Permalink
FIXED: List prefix inside fenced PRE should be ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
odrobnik committed Jun 23, 2017
1 parent c343f82 commit 80a2dab
Showing 1 changed file with 32 additions and 24 deletions.
56 changes: 32 additions & 24 deletions Core/Source/DTMarkdownParser.m
Expand Up @@ -275,35 +275,42 @@ - (void)_findAndMarkSpecialLines
{
specialOfLineBefore = _specialLines[@(lineIndex-1)];

unichar firstChar = [line characterAtIndex:0];

if (firstChar=='-' || firstChar=='=')
if (specialOfLineBefore == DTMarkdownParserSpecialFencedPreStart || specialOfLineBefore == DTMarkdownParserSpecialFencedPreCode)
{
line = [line stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSUInteger lineLen = [line length];

NSUInteger idx=0;
while (idx<lineLen && [line characterAtIndex:idx] == firstChar)
{
idx++;
}
// ignore, cannot start a list
}
else
{
unichar firstChar = [line characterAtIndex:0];

if (idx>=lineLen)
if (firstChar=='-' || firstChar=='=')
{
if (![_ignoredLines containsIndex:lineIndex-1])
line = [line stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSUInteger lineLen = [line length];

NSUInteger idx=0;
while (idx<lineLen && [line characterAtIndex:idx] == firstChar)
{
// full line is this character
[_ignoredLines addIndex:lineIndex];

if (firstChar=='=')
{
_specialLines[@(lineIndex-1)] = DTMarkdownParserSpecialTagH1;
didFindSpecial = YES;
}
else if (firstChar=='-')
idx++;
}

if (idx>=lineLen)
{
if (![_ignoredLines containsIndex:lineIndex-1])
{
_specialLines[@(lineIndex-1)] = DTMarkdownParserSpecialTagH2;
didFindSpecial = YES;
// full line is this character
[_ignoredLines addIndex:lineIndex];

if (firstChar=='=')
{
_specialLines[@(lineIndex-1)] = DTMarkdownParserSpecialTagH1;
didFindSpecial = YES;
}
else if (firstChar=='-')
{
_specialLines[@(lineIndex-1)] = DTMarkdownParserSpecialTagH2;
didFindSpecial = YES;
}
}
}
}
Expand Down Expand Up @@ -359,6 +366,7 @@ - (void)_findAndMarkSpecialLines
if (specialOfLineBefore == DTMarkdownParserSpecialFencedPreCode || specialOfLineBefore == DTMarkdownParserSpecialFencedPreStart)
{
_specialLines[@(lineIndex)] = DTMarkdownParserSpecialFencedPreCode;
didFindSpecial = YES;
}
}

Expand Down

0 comments on commit 80a2dab

Please sign in to comment.