-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from tattali/catalina-support
Catalina support
- Loading branch information
Showing
15 changed files
with
780 additions
and
509 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ColumnLimit: 120 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,36 @@ | ||
#import <QuickLook/QuickLook.h> | ||
#import <Cocoa/Cocoa.h> | ||
#include "markdown.h" | ||
#import <CoreFoundation/CoreFoundation.h> | ||
#import <CoreServices/CoreServices.h> | ||
#import <Foundation/Foundation.h> | ||
#import <QuickLook/QuickLook.h> | ||
|
||
#import "markdown.h" | ||
|
||
OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, | ||
CFStringRef contentTypeUTI, CFDictionaryRef options); | ||
void CancelPreviewGeneration(void *thisInterface, QLPreviewRequestRef preview); | ||
|
||
/* ----------------------------------------------------------------------------- | ||
Generate a preview for file | ||
This function's job is to create preview for designated file | ||
-------------------------------------------------------------------------- */ | ||
|
||
OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, | ||
CFURLRef url, CFStringRef contentTypeUTI, | ||
CFDictionaryRef options) | ||
{ | ||
@autoreleasepool { | ||
NSData *data = renderMarkdown((__bridge NSURL*) url); | ||
|
||
if (data) { | ||
NSDictionary *props = [[NSDictionary alloc] init]; | ||
QLPreviewRequestSetDataRepresentation(preview, (__bridge CFDataRef)data, kUTTypeHTML, (__bridge CFDictionaryRef)props); | ||
} | ||
|
||
return noErr; | ||
} | ||
----------------------------------------------------------------------------- | ||
*/ | ||
OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, | ||
CFStringRef contentTypeUTI, CFDictionaryRef options) { | ||
|
||
NSString *content = renderMarkdown((__bridge NSURL *)url); | ||
|
||
CFDictionaryRef previewProperties = (__bridge CFDictionaryRef) @{ | ||
(__bridge NSString *)kQLPreviewPropertyTextEncodingNameKey : @"UTF-8", | ||
(__bridge NSString *)kQLPreviewPropertyMIMETypeKey : @"text/html", | ||
}; | ||
|
||
QLPreviewRequestSetDataRepresentation(preview, (__bridge CFDataRef)[content dataUsingEncoding:NSUTF8StringEncoding], | ||
kUTTypeHTML, previewProperties); | ||
|
||
return noErr; | ||
} | ||
|
||
void CancelPreviewGeneration(void* thisInterface, QLPreviewRequestRef preview) | ||
{ | ||
// implement only if supported | ||
void CancelPreviewGeneration(void *thisInterface, QLPreviewRequestRef preview) { | ||
// Implement only if supported | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,59 @@ | ||
#import <QuickLook/QuickLook.h> | ||
#import <Cocoa/Cocoa.h> | ||
#import <CoreFoundation/CoreFoundation.h> | ||
#import <CoreServices/CoreServices.h> | ||
#import <Foundation/Foundation.h> | ||
#import <QuickLook/QuickLook.h> | ||
#import <WebKit/WebKit.h> | ||
#include "markdown.h" | ||
|
||
/* ----------------------------------------------------------------------------- | ||
Generate a thumbnail for file | ||
|
||
This function's job is to create thumbnail for designated file as fast as | ||
possible | ||
-------------------------------------------------------------------------- */ | ||
OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thumbnail, CFURLRef url, | ||
CFStringRef contentTypeUTI, CFDictionaryRef options, CGSize maxSize); | ||
void CancelThumbnailGeneration(void *thisInterface, QLThumbnailRequestRef thumbnail); | ||
|
||
//The minimum aspect ratio (width / height) of a thumbnail. | ||
#define MINIMUM_ASPECT_RATIO (1.0/2.0) | ||
|
||
|
||
OSStatus GenerateThumbnailForURL(void *thisInterface, | ||
QLThumbnailRequestRef thumbnail, | ||
CFURLRef url, CFStringRef contentTypeUTI, | ||
CFDictionaryRef options, CGSize maxSize) | ||
{ | ||
@autoreleasepool { | ||
NSData *data = renderMarkdown((__bridge NSURL*) url); | ||
/* ----------------------------------------------------------------------------- | ||
Generate a thumbnail for file | ||
This function's job is to create thumbnail for designated file as fast as possible | ||
----------------------------------------------------------------------------- */ | ||
|
||
if (data) { | ||
NSRect viewRect = NSMakeRect(0.0, 0.0, 600.0, 800.0); | ||
float scale = maxSize.height / 800.0; | ||
NSSize scaleSize = NSMakeSize(scale, scale); | ||
CGSize thumbSize = NSSizeToCGSize( | ||
NSMakeSize((maxSize.width * (600.0/800.0)), | ||
maxSize.height)); | ||
OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thumbnail, CFURLRef url, | ||
CFStringRef contentTypeUTI, CFDictionaryRef options, CGSize maxSize) { | ||
|
||
WebView* webView = [[WebView alloc] initWithFrame: viewRect]; | ||
[webView scaleUnitSquareToSize: scaleSize]; | ||
[[[webView mainFrame] frameView] setAllowsScrolling:NO]; | ||
[[webView mainFrame] loadData: data | ||
MIMEType: @"text/html" | ||
textEncodingName: @"utf-8" | ||
baseURL: nil]; | ||
NSString *content = [NSString stringWithContentsOfURL:(__bridge NSURL *)url encoding:NSUTF8StringEncoding error:nil]; | ||
|
||
while([webView isLoading]) { | ||
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true); | ||
} | ||
if (content) { | ||
// Encapsulate the content of the .strings file in HTML | ||
NSData *data = [content dataUsingEncoding:NSUTF8StringEncoding]; | ||
|
||
[webView display]; | ||
NSRect _rect = NSMakeRect(0.0, 0.0, 600.0, 800.0); | ||
float _scale = maxSize.height / 800.0; | ||
NSSize _scaleSize = NSMakeSize(_scale, _scale); | ||
CGSize _thumbSize = NSSizeToCGSize(NSMakeSize((maxSize.width * (600.0 / 800.0)), maxSize.height)); | ||
|
||
CGContextRef context = | ||
QLThumbnailRequestCreateContext(thumbnail, thumbSize, false, NULL); | ||
// Create the webview to display the thumbnail | ||
WebView *_webView = [[WebView alloc] initWithFrame:_rect]; | ||
[_webView scaleUnitSquareToSize:_scaleSize]; | ||
[_webView.mainFrame.frameView setAllowsScrolling:NO]; | ||
[_webView.mainFrame loadData:data MIMEType:@"text/html" textEncodingName:@"utf-8" baseURL:nil]; | ||
|
||
if (context) { | ||
NSGraphicsContext* nsContext = | ||
[NSGraphicsContext | ||
graphicsContextWithGraphicsPort: (void*) context | ||
flipped: [webView isFlipped]]; | ||
while ([_webView isLoading]) | ||
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true); | ||
[_webView display]; | ||
|
||
[webView displayRectIgnoringOpacity: [webView bounds] | ||
inContext: nsContext]; | ||
// Draw the webview in the correct context | ||
CGContextRef _context = QLThumbnailRequestCreateContext(thumbnail, _thumbSize, false, NULL); | ||
if (_context) { | ||
NSGraphicsContext *_graphicsContext = [NSGraphicsContext graphicsContextWithGraphicsPort:(void *)_context | ||
flipped:_webView.isFlipped]; | ||
[_webView displayRectIgnoringOpacity:_webView.bounds inContext:_graphicsContext]; | ||
|
||
QLThumbnailRequestFlushContext(thumbnail, context); | ||
QLThumbnailRequestFlushContext(thumbnail, _context); | ||
|
||
CFRelease(context); | ||
} | ||
CFRelease(_context); | ||
} | ||
} | ||
|
||
return noErr; | ||
} | ||
return noErr; | ||
} | ||
|
||
void CancelThumbnailGeneration(void* thisInterface, QLThumbnailRequestRef thumbnail) | ||
{ | ||
// implement only if supported | ||
void CancelThumbnailGeneration(void *thisInterface, QLThumbnailRequestRef thumbnail) { | ||
// implement only if supported | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#include "discount/markdown.h" | ||
|
||
char* convert_markdown_to_string(const char *str) | ||
{ | ||
char *out = NULL; | ||
|
||
Document *blob = mkd_string((char *)str, strlen(str), 0); | ||
mkd_compile(blob, MKD_EXTRA_FOOTNOTE); | ||
int sz = mkd_document(blob, &out); | ||
|
||
if(sz == 0) | ||
return NULL; | ||
|
||
return out; | ||
} | ||
char *convert_markdown_to_string(const char *str) { | ||
char *out = NULL; | ||
|
||
Document *blob = mkd_string((char *)str, strlen(str), 0); | ||
mkd_compile(blob, MKD_EXTRA_FOOTNOTE); | ||
int sz = mkd_document(blob, &out); | ||
|
||
if (sz == 0) | ||
return NULL; | ||
|
||
return out; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
char* convert_markdown_to_string(const char *str); | ||
char *convert_markdown_to_string(const char *str); |
Oops, something went wrong.