Permalink
Browse files

Implemented the ORCDiscount framework.

  • Loading branch information...
1 parent 2b98e93 commit 36691b0cd69347489d036ba34105f33465a25c3c @mugginsoft mugginsoft committed Jul 9, 2011

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -5,19 +5,16 @@
***************************************************************************/
+#import "ORCDiscount.h"
#import "MyDocument.h"
-#include "discountWrapper.h"
NSString *kMarkdownDocumentType = @"MarkdownDocumentType";
-@implementation MyDocument
+@interface MyDocument()
+- (void)htmlPreviewTimer:(NSTimer*)timer_;
+@end
-- (NSString*)markdown2html:(NSString*)markdown_ {
- if (!markdown_)
- return @"";
-
- return discountToHTML(markdown_);
-}
+@implementation MyDocument
- (id)init {
self = [super init];
@@ -95,29 +92,16 @@ - (BOOL)readFromURL:(NSURL*)absoluteURL_ ofType:(NSString*)typeName_ error:(NSEr
}
- (void)textDidChange:(NSNotification*)notification_ {
+
+#pragma unused(notification_)
+
whenToUpdatePreview = [NSDate timeIntervalSinceReferenceDate] + 0.5;
}
-- (NSString *)HTMLPage:(NSString *)markdownHTML withCSSHTML:(NSString *)cssHTML
-{
- return [NSString stringWithFormat:
- @"<!DOCTYPE html>\n<html>\n<head>\n<title>%@</title>\n%@</head>\n<body>%@</body>\n</html>",
- @"Markdown Preview",
- cssHTML,
- markdownHTML
- ];
-}
-
-- (NSString *)HTMLPage:(NSString *)markdownHTML withCSSFromURL:(NSURL *)cssURL
-{
- NSString *cssHTML = [NSString stringWithFormat:
- @"<link rel=\"stylesheet\" type=\"text/css\" href=\"%@\">\n",
- [cssURL absoluteString]
- ];
- return [self HTMLPage:markdownHTML withCSSHTML:cssHTML];
-}
-
- (void)htmlPreviewTimer:(NSTimer*)timer_ {
+
+#pragma unused(timer_)
+
if ([NSDate timeIntervalSinceReferenceDate] >= whenToUpdatePreview) {
whenToUpdatePreview = [[NSDate distantFuture] timeIntervalSinceReferenceDate];
@@ -133,12 +117,15 @@ - (void)htmlPreviewTimer:(NSTimer*)timer_ {
hasSavedOrigin = YES;
}
NSURL *css = [[NSBundle mainBundle] URLForResource:@"styles" withExtension:@"css"];
- NSString *html = [self HTMLPage:[self markdown2html:[markdownSource string]] withCSSFromURL:css];
+ NSString *html = [ORCDiscount HTMLPage:[ORCDiscount markdown2HTML:[markdownSource string]] withCSSFromURL:css];
[[htmlPreviewWebView mainFrame] loadHTMLString:html baseURL:[self fileURL]];
}
}
- (void)webView:(WebView*)sender_ didFinishLoadForFrame:(WebFrame*)frame_ {
+
+#pragma unused(sender_)
+
if ([htmlPreviewWebView mainFrame] == frame_ && hasSavedOrigin) {
hasSavedOrigin = NO;
if (savedAtBottom)
@@ -149,8 +136,11 @@ - (void)webView:(WebView*)sender_ didFinishLoadForFrame:(WebFrame*)frame_ {
}
- (IBAction)copyGeneratedHTMLAction:(id)sender {
+
+ #pragma unused(sender)
+
[[NSPasteboard generalPasteboard] declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
- [[NSPasteboard generalPasteboard] setString:[self markdown2html:[markdownSource string]] forType:NSStringPboardType];
+ [[NSPasteboard generalPasteboard] setString:[ORCDiscount markdown2HTML:[markdownSource string]] forType:NSStringPboardType];
}
@end
View
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIdentifier</key>
+ <string>com.yourcompany.${PRODUCT_NAME:rfc1034identifier}</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundlePackageType</key>
+ <string>FMWK</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1</string>
+</dict>
+</plist>
View
@@ -0,0 +1,18 @@
+/*
+ * ORCDiscount.h
+ * MarkdownLive
+ *
+ * Created by Jonathan on 09/07/2011.
+ * Copyright 2011 mugginsoft.com. All rights reserved.
+ *
+ */
+#import <Cocoa/Cocoa.h>
+
+@interface ORCDiscount : NSObject {
+}
+
++ (NSString *)markdown2HTML:(NSString *)markdown;
++ (NSString *)HTMLPage:(NSString *)markdownHTML withCSSHTML:(NSString *)cssHTML;
++ (NSString *)HTMLPage:(NSString *)markdownHTML withCSSFromURL:(NSURL *)cssURL;
+
+@end
View
@@ -0,0 +1,41 @@
+//
+// ORCDiscount.m
+// MarkdownLive
+//
+// Created by Jonathan on 09/07/2011.
+// Copyright 2011 mugginsoft.com. All rights reserved.
+//
+
+
+#import "ORCDiscount.h"
+#import "discountWrapper.h"
+
+@implementation ORCDiscount
+
++ (NSString *)markdown2HTML:(NSString *)markdown_ {
+ if (!markdown_) {
+ return @"";
+ }
+
+ return discountToHTML(markdown_);
+}
+
++ (NSString *)HTMLPage:(NSString *)markdownHTML withCSSHTML:(NSString *)cssHTML
+{
+ return [NSString stringWithFormat:
+ @"<!DOCTYPE html>\n<html>\n<head>\n<title>%@</title>\n%@</head>\n<body>%@</body>\n</html>",
+ @"Markdown Preview",
+ cssHTML,
+ markdownHTML
+ ];
+}
+
++ (NSString *)HTMLPage:(NSString *)markdownHTML withCSSFromURL:(NSURL *)cssURL
+{
+ NSString *cssHTML = [NSString stringWithFormat:
+ @"<link rel=\"stylesheet\" type=\"text/css\" href=\"%@\">\n",
+ [cssURL absoluteString]
+ ];
+ return [self HTMLPage:markdownHTML withCSSHTML:cssHTML];
+}
+@end
View
@@ -0,0 +1,8 @@
+## MarkdownLive
+
+A Cocoa markdown preview editor using [Discount][discount].
+
+Implements the ORCDiscount framework.
+
+
+[discount]: https://github.com/Orc/discount
@@ -0,0 +1,12 @@
+/*
+ * Discount.h
+ * MarkdownLive
+ *
+ * Created by Jonathan on 09/07/2011.
+ * Copyright 2011 mugginsoft.com. All rights reserved.
+ *
+ */
+
+#include "markdownWrapper.h"
+#include "mkdioWrapper.h"
+#include "discountWrapper.h"

0 comments on commit 36691b0

Please sign in to comment.