forked from toland/qlmarkdown
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmarkdown.m
More file actions
22 lines (20 loc) · 1.29 KB
/
markdown.m
File metadata and controls
22 lines (20 loc) · 1.29 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' />"
"<base href='%@' />"
"<style type=\"text/css\">%@</style>"
"</head>"
"<body>%@</body>"
"</html>",
[[[url URLByDeletingLastPathComponent] filePathURL] absoluteString], styles, [NSString stringWithUTF8String:output]];
free(output);
return [html dataUsingEncoding:NSUTF8StringEncoding];
}