Permalink
Browse files

Taskpaper detection (looks for Archive: or a @taskpaper tag) and rend…

…ering for preview
  • Loading branch information...
1 parent 2234f49 commit 7fd4c21e167fe3230c6dab2298fd86f951052016 @ttscoff committed May 24, 2011
Showing with 105 additions and 7 deletions.
  1. +5 −5 Info.plist
  2. +1 −0 NSString_MultiMarkdown.h
  3. +47 −1 NSString_MultiMarkdown.m
  4. +4 −0 Notation.xcodeproj/project.pbxproj
  5. +1 −1 PreviewController.m
  6. +47 −0 tp2md.rb
View
@@ -154,7 +154,7 @@
<dict>
<key>CFBundleURLSchemes</key>
<array>
- <string>nv</string>
+ <string>nvalt</string>
</array>
</dict>
</array>
@@ -216,6 +216,10 @@
</array>
<key>OSAScriptingDefinition</key>
<string>Notation.sdef</string>
+ <key>SmartCrashReports_CompanyName</key>
+ <string>Notational.net</string>
+ <key>SmartCrashReports_EmailTicket</key>
+ <string>SCR-51ED0F7B2A</string>
<key>SUCheckAtStartup</key>
<false/>
<key>SUFeedURL</key>
@@ -224,10 +228,6 @@
<string>dsa_pub.pem</string>
<key>SUScheduledCheckInterval</key>
<real>345600</real>
- <key>SmartCrashReports_CompanyName</key>
- <string>Notational.net</string>
- <key>SmartCrashReports_EmailTicket</key>
- <string>SCR-51ED0F7B2A</string>
<key>UTExportedTypeDeclarations</key>
<array/>
<key>UTImportedTypeDeclarations</key>
@@ -17,5 +17,6 @@
+ (NSString*)documentWithProcessedMultiMarkdown:(NSString*)inputString;
+ (NSString*)xhtmlWithProcessedMultiMarkdown:(NSString*)inputString;
+ (NSString*)processMultiMarkdown:(NSString*)inputString;
++ (NSString*)processTaskPaper:(NSString*)inputString;
@end
@@ -35,10 +35,56 @@ +(NSString*)mmdDirectory {
return bundlePath;
} // mmdDirectory
++(NSString*)tp2mdDirectory {
+ // fallback path in this program's directiory
+ NSString *bundlePath = [[[NSBundle mainBundle] resourcePath]
+ stringByAppendingPathComponent:@"tp2md.rb"];
+ return bundlePath;
+}
+
++(NSString*)processTaskPaper:(NSString*)inputString
+{
+ NSString* mdScriptPath = [[self class] tp2mdDirectory];
+
+ NSTask* task = [[[NSTask alloc] init] autorelease];
+ NSMutableArray* args = [NSMutableArray array];
+
+ [task setArguments:args];
+
+ NSPipe* stdinPipe = [NSPipe pipe];
+ NSPipe* stdoutPipe = [NSPipe pipe];
+ NSFileHandle* stdinFileHandle = [stdinPipe fileHandleForWriting];
+ NSFileHandle* stdoutFileHandle = [stdoutPipe fileHandleForReading];
+
+ [task setStandardInput:stdinPipe];
+ [task setStandardOutput:stdoutPipe];
+
+ [task setLaunchPath: [mdScriptPath stringByExpandingTildeInPath]];
+ [task launch];
+
+ [stdinFileHandle writeData:[inputString dataUsingEncoding:NSUTF8StringEncoding]];
+ [stdinFileHandle closeFile];
+
+ NSData* outputData = [stdoutFileHandle readDataToEndOfFile];
+ NSString* outputString = [[[NSString alloc] initWithData:outputData encoding:NSUTF8StringEncoding] autorelease];
+ [stdoutFileHandle closeFile];
+
+ [task waitUntilExit];
+
+ return outputString;
+
+}
+
+
+(NSString*)processMultiMarkdown:(NSString*)inputString
{
+ NSRange archiveFoundRange = [inputString rangeOfString:@"Archive:"];
+ NSRange tagFoundRange = [inputString rangeOfString:@"@taskpaper"];
+ if (archiveFoundRange.location != NSNotFound || tagFoundRange.location != NSNotFound) {
+ inputString = [self processTaskPaper:inputString];
+ }
NSString* mdScriptPath = [[self class] mmdDirectory];
-
+ NSString* tpScriptPath = [[self class] tp2mdDirectory];
NSTask* task = [[[NSTask alloc] init] autorelease];
NSMutableArray* args = [NSMutableArray array];
@@ -260,6 +260,7 @@
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
+ 93099628138BD61000368C45 /* tp2md.rb in Resources */ = {isa = PBXBuildFile; fileRef = 93099627138BD61000368C45 /* tp2md.rb */; };
93A158BC133C304D00E1E7DA /* Markdownify.nvhelp in Resources */ = {isa = PBXBuildFile; fileRef = 93A158BB133C304D00E1E7DA /* Markdownify.nvhelp */; };
93A158BE133C497400E1E7DA /* Notality.icns in Resources */ = {isa = PBXBuildFile; fileRef = 93A158BD133C497400E1E7DA /* Notality.icns */; };
93B348281371547800658F98 /* HUDIconLock.png in Resources */ = {isa = PBXBuildFile; fileRef = 93B348241371547800658F98 /* HUDIconLock.png */; };
@@ -716,6 +717,7 @@
5CFC3A5013327EF9000B4792 /* pt */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = pt; path = pt.lproj/TagEditingManager.xib; sourceTree = "<group>"; };
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
8D1107320486CEB800E47090 /* nvALT.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = nvALT.app; sourceTree = BUILT_PRODUCTS_DIR; };
+ 93099627138BD61000368C45 /* tp2md.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = tp2md.rb; sourceTree = "<group>"; };
93A158BB133C304D00E1E7DA /* Markdownify.nvhelp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Markdownify.nvhelp; sourceTree = "<group>"; };
93A158BD133C497400E1E7DA /* Notality.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = Notality.icns; sourceTree = "<group>"; };
93B348241371547800658F98 /* HUDIconLock.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = HUDIconLock.png; path = Images/HUDIconLock.png; sourceTree = "<group>"; };
@@ -1233,6 +1235,7 @@
5C96F5A8131C379200A2E4AC /* Markup */ = {
isa = PBXGroup;
children = (
+ 93099627138BD61000368C45 /* tp2md.rb */,
5C96F617131C380C00A2E4AC /* Markdown_1.0.1 */,
5C96F610131C380100A2E4AC /* Textile_2.12 */,
5C96F5B2131C37F500A2E4AC /* MultiMarkdown */,
@@ -1501,6 +1504,7 @@
93B3482A1371547800658F98 /* HUDIconSave.png in Resources */,
93B3482B1371547800658F98 /* HUDIconShare.png in Resources */,
93B90E84138601C100BEC5FB /* LICENSE.txt in Resources */,
+ 93099628138BD61000368C45 /* tp2md.rb in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
@@ -202,7 +202,7 @@ - (void)webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window
- (void)webView:(WebView *)sender decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
NSString *targetURL = [[request URL] scheme];
- if ([targetURL isEqual:@"http"]) {
+ if ([targetURL isEqual:@"http"] || [targetURL isEqual:@"nvalt"]) {
[[NSWorkspace sharedWorkspace] openURL:[request URL]];
[listener ignore];
} else {
View
@@ -0,0 +1,47 @@
+#!/usr/bin/env ruby -rjcode -Ku
+# Usage: tp2md.rb filename.taskpaper > output.md
+require 'ftools'
+
+input = STDIN.read
+
+header = input.scan(/Format\: .*$/)
+output = ""
+prevlevel = 0
+begin
+ input.split("\n").each {|line|
+ if line =~ /^(\t+)?(.*?):(\s(.*?))?$/
+ tabs = $1
+ project = $2
+ if tabs.nil?
+ output += "\n## #{project} ##\n\n"
+ prevlevel = 0
+ else
+ output += "#{tabs.gsub(/^\t/,'')}* **#{project}**\n"
+ prevlevel = tabs.length
+ end
+ elsif line =~ /^(\t+)?\- (.*)$/
+ task = $2
+ tabs = $1.nil? ? '' : $1
+ task = "*<del>#{task}</del>*" if task =~ /@done/
+ if tabs.length - prevlevel > 1
+ tabs = "\t"
+ prevlevel.times {|i| tabs += "\t"}
+ end
+ tabs = '' if prevlevel == 0 && tabs.length > 1
+ output += "#{tabs.gsub(/^\t/,'')}* #{task.strip}\n"
+ prevlevel = tabs.length
+ else
+ next if line =~ /^\s*$/
+ tabs = ""
+ prevlevel-1.times {|i| tabs += "\t"}
+ output += "#{tabs}> #{line.strip}\n\n"
+ end
+ }
+rescue => err
+ puts "Exception: #{err}"
+ err
+end
+
+puts header.join("\n") + "\n" unless header.nil?
+puts "<style>.tag strong {font-weight:normal;color:#555} .tag a {text-decoration:none;border:none;color:#777}</style>"
+puts output.gsub(/(@[^ \n\r\(]+)((\()([^\)]+)(\)))?/,"<em class=\"tag\"><a href=\"nvalt://find/\\0\">\\1\\3<strong>\\4</strong>\\5</a></em>")

0 comments on commit 7fd4c21

Please sign in to comment.