Skip to content
Browse files

Added third pane with live Markdown preview

  • Loading branch information...
Steven Frank
Steven Frank committed Feb 11, 2010
1 parent 12c4b28 commit ce6bf6e5cc3a635ed51fbecffd486ee97808220e
@@ -27,6 +27,7 @@
IBOutlet NSWindow *window;
IBOutlet NSPanel *syncWaitPanel;
IBOutlet NSProgressIndicator *syncWaitSpinner;
IBOutlet WebView *webView;
NSToolbar *toolbar;
NSToolbarItem *dualFieldItem;
TitlebarButton *titleBarButton;
@@ -24,9 +24,16 @@
#import "MultiplePageView.h"
#import "URLGetter.h"
#import "LinearDividerShader.h"
#import "NSString-Markdown.h"
#import <WebKit/WebArchive.h>
#include <Carbon/Carbon.h>

@interface AppController ()

- (void)requestPreviewUpdate;


@implementation AppController

//an instance of this class is designated in the nib as the delegate of the window, nstextfield and two nstextviews
@@ -1100,7 +1107,8 @@ - (BOOL)displayContentsForNoteAtIndex:(int)noteIndex {

//restore string
[[textView textStorage] setAttributedString:[note contentString]];

[self requestPreviewUpdate];

//[textView setAutomaticallySelectedRange:NSMakeRange(0,0)];

//highlight terms--delay this, too
@@ -1130,6 +1138,7 @@ - (void)textDidChange:(NSNotification *)aNotification {

if (textObject == textView) {
[currentNote setContentString:[textView textStorage]];
[self requestPreviewUpdate];

@@ -1390,6 +1399,7 @@ - (void)contentsUpdatedForNote:(NoteObject*)aNoteObject {
if (aNoteObject == currentNote) {

[[textView textStorage] setAttributedString:[aNoteObject contentString]];
[self requestPreviewUpdate];

@@ -1512,4 +1522,20 @@ - (NSWindow*)window {
return window;

- (void)requestPreviewUpdate
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(preview:) object:nil];

[self performSelector:@selector(preview:) withObject:nil afterDelay:0.5];

- (void)preview:(id)context
NSString* processedString = [NSString stringWithProcessedMarkdown:[textView string]];
NSString* htmlString = [NSString stringWithFormat:@"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"\"><html><head><style type=\"text/css\">body { font-family: Helvetica, sans-serif; }</style></head><body>%@</body></html>", processedString];

[[webView mainFrame] loadHTMLString:htmlString baseURL:nil];


Large diffs are not rendered by default.

Binary file not shown.
@@ -0,0 +1,30 @@
Copyright (c) 2004, John Gruber
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

* Neither the name "Markdown" nor the names of its contributors may
be used to endorse or promote products derived from this software
without specific prior written permission.

This software is provided by the copyright holders and contributors "as
is" and any express or implied warranties, including, but not limited
to, the implied warranties of merchantability and fitness for a
particular purpose are disclaimed. In no event shall the copyright owner
or contributors be liable for any direct, indirect, incidental, special,
exemplary, or consequential damages (including, but not limited to,
procurement of substitute goods or services; loss of use, data, or
profits; or business interruption) however caused and on any theory of
liability, whether in contract, strict liability, or tort (including
negligence or otherwise) arising in any way out of the use of this
software, even if advised of the possibility of such damage.

0 comments on commit ce6bf6e

Please sign in to comment.
You can’t perform that action at this time.