Streaming Preview

By opening Preview->Streaming Preview, Marked can receive realtime updates from other applications without requiring a file to watch. This allows near-instant updates as changes are made to the document, but requires that the application directly integrate with Marked.

nvALT, nvUltra, The Archive, and Drafts all demonstrate this integration. Simply open the Streaming Preview in Marked, enable Marked Streaming Preview in your app of choice, and then start typing. Your updates should show up in the preview in (near) realtime.


To integrate the Streaming Preview with your app, you just need to put the markdown text to preview on a named clipboard. Use the following code (Objective-C) to update, preferably on a didEndEditing method or at throttled intervals:

NSString *rawString = @"the text to process";
// pasteboard *must* be named 'mkStreamingPreview'
NSPasteboard* pb = [NSPasteboard pasteboardWithName:@"mkStreamingPreview"];
[pb clearContents];
[pb setString:rawString forType:(NSString*)kUTTypeUTF8PlainText];

Declaring a Base URL for relative assets

You can also provide a base url for the streaming preview, allowing relative urls in images and other assets to function as they would in the source app. If the base URL includes a filename, its name and extension will be made available to custom processors, but it’s not required to do so. To include the base URL, simply put an NSURL object into the clipboard:

NSString *rawString = @"The text to be processed\n\n![](images/screenshots/mainwindow-feature-stats.jpg)";
NSURL *baseURL = [NSURL fileURLWithPath:@"/Users/username/Documents/HelpDocs/Main"];
NSPasteboard* pb = [NSPasteboard pasteboardWithName:@"mkStreamingPreview"];
[pb clearContents];
[pb writeObjects:@[rawString, baseURL]];

If the Mac App Store version of Marked is being used and the baseURL isn’t accessible via sandboxing, permission will be requested the first time the URL is loaded in the preview.

Declaring the Source Application

Apps can also declare themselves as the source of the preview content by including a source metadata line. This will usually be accomplished within an HTML comment to allow compatibility with both GFM and MultiMarkdown processors. Simply state the app’s name or bundle id:


Opening the Streaming Preview Programatically

Your app can also open the Streaming Preview programmatically using the x-marked://stream/ url handler method. This method also accepts an x-success parameter in which you can pass a bundle ID of an app to activate upon completion.

Next up: HTML Specific Settings

Search | Support Site | Knowledgebase | Legal | Privacy | Twitter