Skip to content

Commit

Permalink
Simplify the generated HTML code
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasbynens committed Nov 3, 2013
1 parent e9826f2 commit 5155931
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions markdown.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,24 @@
pathForResource:@"styles" ofType:@"css"]
encoding:NSUTF8StringEncoding
error:nil];

NSStringEncoding usedEncoding = 0;
NSError *e = nil;

NSString *source = [NSString stringWithContentsOfURL:url usedEncoding:&usedEncoding error:&e];

if (usedEncoding == 0) {
NSLog(@"Wasn't able to determine encoding for file “%@", [url path]);
}

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>"
NSString *html = [NSString stringWithFormat:@"<!DOCTYPE html>"
"<meta charset=utf-8>"
"<style>%@</style>"
"<base href=\"%@\"/>"
"</head>"
"<body>%@</body>"
"</html>",
"%@",
styles, url, [NSString stringWithUTF8String:output]];

free(output);
return [html dataUsingEncoding:NSUTF8StringEncoding];
}

0 comments on commit 5155931

Please sign in to comment.