Revision: 47634
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at June 12, 2011 04:17 by daknok
Initial Code
+ (NSString *)htmlFromMarkdown:(NSString *)markdown { NSTask *markdownTask = [[NSTask alloc] init]; [markdownTask setLaunchPath:@"/usr/bin/perl"]; [markdownTask setArguments:[NSArray arrayWithObjects:[[NSBundle mainBundle] pathForResource:@"Markdown" ofType:@"pl"], nil]]; NSPipe *markdownPipe = [NSPipe pipe]; NSPipe *htmlPipe = [NSPipe pipe]; [markdownTask setStandardInput:markdownPipe]; [markdownTask setStandardOutput:htmlPipe]; [markdownTask launch]; NSData *markdownData = [markdown dataUsingEncoding:NSUTF8StringEncoding]; [[markdownPipe fileHandleForWriting] writeData:markdownData]; [[markdownPipe fileHandleForWriting] closeFile]; NSString *output = [[[NSString alloc] initWithData:[[htmlPipe fileHandleForReading] readDataToEndOfFile] encoding:NSUTF8StringEncoding] autorelease]; [markdownTask waitUntilExit]; [markdownTask release]; return output; }
Initial URL
Initial Description
Simply make sure you have `Markdown.pl` (from Daring Fireball) inside of your application bundle's resources folder. Perl has to be installed on the target machine. If you are developing for iOS, you should build Perl for iOS, pack it with the application and change the `markdownTask`'s launch path.
Initial Title
Parsing Markdown with Objective-C using the original Perl script
Initial Tags
Initial Language
Objective C