From 79e8eef4a2ec2fb029c06b07bfba7d19203a0194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Sa=CC=81nchez-Sa=CC=81ez?= Date: Tue, 26 May 2015 23:08:51 +0100 Subject: [PATCH 1/2] GBCommentsProcessor: ignore cross references inside markdown fenced code blocks (``` code ```) --- Processing/GBCommentsProcessor.m | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Processing/GBCommentsProcessor.m b/Processing/GBCommentsProcessor.m index 983d5487..b918d1a5 100644 --- a/Processing/GBCommentsProcessor.m +++ b/Processing/GBCommentsProcessor.m @@ -647,7 +647,7 @@ - (NSString *)stringByPreprocessingNonLinkString:(NSString *)string withFlags:(G if ([string length] == 0) return string; // Formatting markers are fine, except *, which should be converted to **. To simplify cross refs detection, we handle all possible formatting markers though so we can search for cross refs within "clean" formatted text, without worrying about markers interfering with search. Note that we also handle "standard" Markdown nested formats and bold markers here, so that we properly handle cross references within. - NSString *pattern = @"(?s:(\\*__|__\\*|\\*\\*_|_\\*\\*|\\*\\*\\*|___|\\*_|_\\*|\\*\\*|__|\\*|_|==!!==|`)(.+?)\\1)"; + NSString *pattern = @"(?s:(\\*__|__\\*|\\*\\*_|_\\*\\*|\\*\\*\\*|___|\\*_|_\\*|\\*\\*|__|\\*|_|==!!==|```|`)(.+?)\\1)"; NSArray *components = [string arrayOfDictionariesByMatchingRegex:pattern withKeysAndCaptures:@"marker", 1, @"value", 2, nil]; NSRange searchRange = NSMakeRange(0, [string length]); NSMutableString *result = [NSMutableString stringWithCapacity:[string length]]; @@ -669,6 +669,7 @@ - (NSString *)stringByPreprocessingNonLinkString:(NSString *)string withFlags:(G GBProcessingFlag linkFlags = flags; NSString *markdownStartMarker = @""; NSString *markdownEndMarker = nil; + BOOL isFencedCodeBlock = NO; if ([componentMarker isEqualToString:@"*"]) { if (self.settings.useSingleStarForBold) { GBLogDebug(@" - Found '%@' formatted as bold at %@...", [componentText normalizedDescription], self.currentSourceInfo); @@ -682,6 +683,12 @@ - (NSString *)stringByPreprocessingNonLinkString:(NSString *)string withFlags:(G GBLogDebug(@" - Found '%@' formatted as italics at %@...", [componentText normalizedDescription], self.currentSourceInfo); markdownStartMarker = @"_"; } + else if ([componentMarker isEqualToString:@"```"]) { + GBLogDebug(@" - Found '%@' formatted as fenced code block at %@...", [componentText normalizedDescription], self.currentSourceInfo); + markdownStartMarker = @"```"; + isFencedCodeBlock = YES; + linkFlags |= GBProcessingFlagEmbedMarkdownLink; + } else if ([componentMarker isEqualToString:@"`"]) { GBLogDebug(@" - Found '%@' formatted as code at %@...", [componentText normalizedDescription], self.currentSourceInfo); markdownStartMarker = @"`"; @@ -700,8 +707,14 @@ - (NSString *)stringByPreprocessingNonLinkString:(NSString *)string withFlags:(G } if (!markdownEndMarker) markdownEndMarker = markdownStartMarker; - // Get formatted text, convert it's cross references and append proper format markers and string to result. - NSString *convertedText = [self stringByConvertingCrossReferencesInString:componentText withFlags:linkFlags]; + NSString *convertedText = nil; + if (!isFencedCodeBlock) { + // Get formatted text, convert its cross references and append proper format markers and string to result. + convertedText = [self stringByConvertingCrossReferencesInString:componentText withFlags:linkFlags]; + } else { + // Don't process cross references inside fenced code blocks. Code samples frequently use external framework (UIKit, etc.) methods and objects whose references won't be found. + convertedText = componentText; + } [result appendString:markdownStartMarker]; [result appendString:convertedText]; [result appendString:markdownEndMarker]; From fc32c5ac5d59d0b2b26ea3c6e783d9b2c2613061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Sa=CC=81nchez-Sa=CC=81ez?= Date: Tue, 26 May 2015 23:09:10 +0100 Subject: [PATCH 2/2] Bump build number to 1334 --- Application/GBApplicationStringsProvider.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Application/GBApplicationStringsProvider.m b/Application/GBApplicationStringsProvider.m index 00df78e0..4d856713 100644 --- a/Application/GBApplicationStringsProvider.m +++ b/Application/GBApplicationStringsProvider.m @@ -152,7 +152,7 @@ - (NSDictionary *)appledocData { result = [[NSMutableDictionary alloc] init]; [result setObject:@"appledoc" forKey:@"tool"]; [result setObject:@"2.2.1" forKey:@"version"]; - [result setObject:@"1333" forKey:@"build"]; + [result setObject:@"1334" forKey:@"build"]; [result setObject:@"http://appledoc.gentlebytes.com" forKey:@"homepage"]; } return result;