Skip to content

Commit

Permalink
Do not pass front-matter into Markdown parser
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr committed Jul 18, 2014
1 parent 0f4ff8b commit 87fa2a3
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions MacDown/Code/Document/MPRenderer.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 87fa2a3

Please sign in to comment.