SmultronでreSTプレビュー
なんかEditorにreSTプレビューがないとかブヒブヒ話題になってたので。
Smultronは裏設定でプレビュー時にMarkdownを使えるんだけどそれって簡単にreSTにできるよね?
うん!できるさ!汚い事すれば!
Object-C暦1分な私でもできた!
(普通わかるよな。。。。。)
MacPythonな環境なのでこんな感じなんだけど”rst2html.py”は各自の環境に合わせればOK。
*** Desktop/SmultronSource/Classes/SMLPreferencesController.m 2007-03-21 20:46:28.000000000 +0900 --- Desktop/SmultronSource2/Classes/SMLPreferencesController.m 2007-03-23 17:34:54.000000000 +0900 *************** *** 198,203 **** --- 198,204 ---- [dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"SuppressReplaceWarning"]; [dictionary setValue:[NSNumber numberWithInt:-1] forKey:@"IndentWidth"]; [dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"PreviewMarkdown"]; + [dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"PreviewRest"]; [dictionary setValue:@"" forKey:@"BaseURL"]; *** Desktop/SmultronSource/Classes/SMLPreviewController.m 2007-03-21 20:46:28.000000000 +0900 --- Desktop/SmultronSource2/Classes/SMLPreviewController.m 2007-03-23 18:29:29.000000000 +0900 *************** *** 108,115 **** } NSData *data; ! if ([[defaults valueForKey:@"PreviewMarkdown"] boolValue] == NO) { data = [[[SMLMainController sharedInstance] currentText] dataUsingEncoding:NSUTF8StringEncoding]; } else { NSString *temporaryPathMarkdown = [[SMLVariousPerformer sharedInstance] genererateTemporaryPath]; [[[SMLMainController sharedInstance] currentText] writeToFile:temporaryPathMarkdown atomically:YES encoding:[[[[SMLMainController sharedInstance] currentDocument] valueForKey:@"encoding"] intValue] error:nil]; --- 108,130 ---- } NSData *data; ! if ([[defaults valueForKey:@"PreviewMarkdown"] boolValue] == NO && [[defaults valueForKey:@"PreviewRest"] boolValue] == NO) { data = [[[SMLMainController sharedInstance] currentText] dataUsingEncoding:NSUTF8StringEncoding]; + }else if ([[defaults valueForKey:@"PreviewRest"] boolValue] == YES) { + NSString *temporaryPathRest = [[SMLVariousPerformer sharedInstance] genererateTemporaryPath]; + [[[SMLMainController sharedInstance] currentText] writeToFile:temporaryPathRest atomically:YES encoding:[[[[SMLMainController sharedInstance] currentDocument] valueForKey:@"encoding"] intValue] error:nil]; + NSString *temporaryPathHTML = [[SMLVariousPerformer sharedInstance] genererateTemporaryPath]; + NSString *htmlString; + system([[NSString stringWithFormat:@"/Library/Frameworks/Python.framework/Versions/2.4/bin/rst2html.py %@ > %@", temporaryPathRest, temporaryPathHTML] UTF8String]); + if ([[NSFileManager defaultManager] fileExistsAtPath:temporaryPathRest]) { + htmlString = [NSString stringWithContentsOfFile:temporaryPathHTML encoding:[[[[SMLMainController sharedInstance] currentDocument] valueForKey:@"encoding"] intValue] error:nil]; + [[NSFileManager defaultManager] removeFileAtPath:temporaryPathHTML handler:nil]; + } else { + htmlString = [[SMLMainController sharedInstance] currentText]; + } + [[NSFileManager defaultManager] removeFileAtPath:temporaryPathRest handler:nil]; + data = [htmlString dataUsingEncoding:NSUTF8StringEncoding]; + } else { NSString *temporaryPathMarkdown = [[SMLVariousPerformer sharedInstance] genererateTemporaryPath]; [[[SMLMainController sharedInstance] currentText] writeToFile:temporaryPathMarkdown atomically:YES encoding:[[[[SMLMainController sharedInstance] currentDocument] valueForKey:@"encoding"] intValue] error:nil]; *************** *** 151,157 **** - (NSURLRequest *)webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)dataSource { ! if ([[defaults valueForKey:@"PreviewMarkdown"] boolValue] == NO) { NSURL *url = [request URL]; NSURLRequest *noCacheRequest = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:120]; return noCacheRequest; --- 166,172 ---- - (NSURLRequest *)webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)dataSource { ! if ([[defaults valueForKey:@"PreviewMarkdown"] boolValue] == NO && [[defaults valueForKey:@"PreviewRest"] boolValue] == NO) { NSURL *url = [request URL]; NSURLRequest *noCacheRequest = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:120]; return noCacheRequest;
インチキなのでデフォルトでreST機能ONです。
これでプレビューがreSTに!
ていうか元ネタもMarkdown.plキックしてるだけだしねえ。
うくく。