public
Description: QuickLook generator for Markdown files.
Homepage: http://fiatdev.com
Clone URL: git://github.com/toland/qlmarkdown.git
qlmarkdown / markdown.m
100644 22 lines (19 sloc) 1.185 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "markdown.h"
#include "discount/wrapper.h"
 
NSData* renderMarkdown(NSURL* url)
{
    NSString *styles = [NSString stringWithContentsOfFile:[[NSBundle bundleWithIdentifier: @"com.fiatdev.QLMarkdown"]
                                                           pathForResource:@"styles" ofType:@"css"]];
    
    NSString *source = [NSString stringWithContentsOfFile:[url path] encoding:NSUTF8StringEncoding error:nil];
    char *output = convert_markdown_to_string([source UTF8String]);
    NSString *html = [NSString stringWithFormat:@"<html>"
                                                 "<head>"
                                                 "<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />"
                                                 "<style type=\"text/css\">%@</style>"
                                                 "</head>"
                                                 "<body>%@</body>"
                                                 "</html>",
                                                 styles, [NSString stringWithUTF8String:output]];
    
    free(output);
    return [html dataUsingEncoding:NSUTF8StringEncoding];
}