All pastes #487935 Raw Edit

Someone

public text v1 · immutable
·published 2007-05-14 19:02 UTC
rendered paste body
- (NSAttributedString *)filterAttributedString:(NSAttributedString *)inAttributedString context:(id)context {
	NSMutableAttributedString *outAttributedString;
	outAttributedString = [[NSMutableAttributedString alloc] initWithAttributedString:inAttributedString];
	
	// Convert the message to HTML and write it out to a file
	NSString *htmlified = [AIHTMLDecoder encodeHTML:inAttributedString
											headers:NO
										   fontTags:NO /* These settings are pretty arbitrary, experiment */
								 includingColorTags:NO
									  closeFontTags:NO
										  styleTags:YES
						 closeStyleTagsOnFontChange:YES
									 encodeNonASCII:YES
									   encodeSpaces:NO
										 imagesPath:@""
								  attachmentsAsText:NO
						  onlyIncludeOutgoingImages:NO
									 simpleTagsOnly:YES
									 bodyBackground:NO];
	
	[htmlified writeToFile:@"/tmp/AIMsg.text" /* FIXME: This probably shouldn't be hard-coded */
				atomically:NO
				  encoding:NSUTF8StringEncoding
					 error:NULL];
	
	NSLog(@"Markdown path: %@", [NSString stringWithFormat:@"%@/Markdown.pl", [[NSBundle bundleForClass:@"ALMarkdownPlugin"] resourcePath]]);
	
	// Call upon Markdown to process the text
	NSMutableArray *args = [NSMutableArray array];
	[args addObject:[NSString stringWithFormat:@"%@/Markdown.pl", [[NSBundle bundleForClass:@"ALMarkdownPlugin"] resourcePath]]];
	[args addObject:@"-html4tags"];
	[args addObject:@"/tmp/AIMsg.text"];
	
	NSTask *aTask = [[NSTask alloc] init];
	[aTask setLaunchPath:@"/usr/bin/perl"];
	[aTask setArguments:args];
	
	NSPipe *ceciNestPasUnePipe = [NSPipe pipe];
	[aTask setStandardOutput:ceciNestPasUnePipe];
	
	NSLog(@"Starting Markdown...");
	[aTask launch];
	while([aTask isRunning]) { }
	
	// Return the HTML again
	NSData *inData = [[ceciNestPasUnePipe fileHandleForReading] availableData];
	[aTask release];
	
	return [AIHTMLDecoder decodeHTML:[NSString stringWithCharacters:[inData bytes]
															 length:[inData length]]];
}