Created
December 21, 2011 15:36
-
-
Save maddox/1506450 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "NSString+Extras.h" | |
#include "markdown.h" | |
#include "html.h" | |
#include "buffer.h" | |
@implementation NSString (Extras) | |
- (BOOL)containsString:(NSString*)substring{ | |
NSRange range = [[self lowercaseString] rangeOfString:[substring lowercaseString]]; | |
BOOL found = (range.location != NSNotFound); | |
return found; | |
} | |
- (NSString *)toHtml{ | |
const char *prose = [self UTF8String]; | |
struct buf *ib = bufnew(strlen(prose)); | |
bufputs(ib, prose); | |
struct buf *ob = bufnew(64); | |
struct sd_callbacks callbacks; | |
struct html_renderopt options; | |
sdhtml_renderer(&callbacks, &options, 0); | |
struct sd_markdown *markdown = sd_markdown_new(0, 16, &callbacks, &options); | |
sd_markdown_render(ob, ib->data, ib->size, markdown); | |
sd_markdown_free(markdown); | |
NSString *markup = [NSString stringWithUTF8String:bufcstr(ob)]; | |
bufrelease(ib); | |
bufrelease(ob); | |
return markup;} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment