From 87fa2a3a102e2e689ab4db6846e65ce199e33bad Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Fri, 18 Jul 2014 16:20:00 +0800 Subject: [PATCH] Do not pass front-matter into Markdown parser --- MacDown/Code/Document/MPRenderer.m | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/MacDown/Code/Document/MPRenderer.m b/MacDown/Code/Document/MPRenderer.m index ca1681e2..c26f04dd 100644 --- a/MacDown/Code/Document/MPRenderer.m +++ b/MacDown/Code/Document/MPRenderer.m @@ -57,8 +57,9 @@ return urls; } -static NSString *MPHTMLFromMarkdown(NSString *text, int flags, BOOL smartypants, - hoedown_renderer *renderer) +static NSString *MPHTMLFromMarkdown( + NSString *text, int flags, BOOL smartypants, NSString *frontMatter, + hoedown_renderer *renderer) { NSData *inputData = [text dataUsingEncoding:NSUTF8StringEncoding]; hoedown_markdown *markdown = hoedown_markdown_new(flags, 15, renderer); @@ -74,6 +75,8 @@ NSString *result = [NSString stringWithUTF8String:hoedown_buffer_cstr(ob)]; hoedown_markdown_free(markdown); hoedown_buffer_free(ob); + if (frontMatter) + result = [NSString stringWithFormat:@"%@\n%@", frontMatter, result]; return result; } @@ -391,21 +394,19 @@ - (void)parse BOOL smartypants = [delegate rendererHasSmartyPants:self]; BOOL hasFrontMatter = [delegate rendererDetectsFrontMatter:self]; + NSString *frontMatter = nil; NSString *markdown = [self.dataSource rendererMarkdown:self]; if (hasFrontMatter) { NSRange restRange = NSMakeRange(0, markdown.length); - NSString *frontMatter = [self frontMatterFromMarkdown:markdown + frontMatter = [self frontMatterFromMarkdown:markdown restRange:&restRange]; if (frontMatter.length) - { - NSString *rest = [markdown substringWithRange:restRange]; - markdown = [NSString stringWithFormat:@"%@\n%@", frontMatter, rest]; - } + markdown = [markdown substringWithRange:restRange]; } self.currentHtml = MPHTMLFromMarkdown( - markdown, extensions, smartypants, self.htmlRenderer); + markdown, extensions, smartypants, frontMatter, self.htmlRenderer); self.extensions = extensions; self.smartypants = smartypants;