Skip to content

Commit a017222

Browse files
committed
Initial commit
0 parents  commit a017222

File tree

12 files changed

+2632
-0
lines changed

12 files changed

+2632
-0
lines changed

English.lproj/InfoPlist.strings

418 Bytes
Binary file not shown.

GeneratePreviewForURL.m

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#import <Foundation/Foundation.h>
2+
#import <QuickLook/QuickLook.h>
3+
4+
#import "QLMarkdown.h"
5+
6+
/* -----------------------------------------------------------------------------
7+
Generate a preview for file
8+
9+
This function's job is to create preview for designated file
10+
----------------------------------------------------------------------------- */
11+
12+
13+
OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options)
14+
{
15+
NSString *htmlString = ConvertURLToText((NSURL *)url);
16+
CFDataRef data = (CFDataRef) [htmlString dataUsingEncoding:NSUTF8StringEncoding];
17+
CFDictionaryRef props = (CFDictionaryRef) [NSDictionary dictionary];
18+
QLPreviewRequestSetDataRepresentation(preview, data, kUTTypeHTML, props);
19+
return noErr;
20+
}
21+
22+
void CancelPreviewGeneration(void* thisInterface, QLPreviewRequestRef preview)
23+
{
24+
// implement only if supported
25+
}

GenerateThumbnailForURL.m

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#import <Cocoa/Cocoa.h>
2+
#include <CoreServices/CoreServices.h>
3+
#include <QuickLook/QuickLook.h>
4+
#import <WebKit/WebKit.h>
5+
6+
#import "QLMarkdown.h"
7+
8+
/* -----------------------------------------------------------------------------
9+
Generate a thumbnail for file
10+
11+
This function's job is to create thumbnail for designated file as fast as possible
12+
----------------------------------------------------------------------------- */
13+
14+
OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thumbnail, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options, CGSize maxSize)
15+
{
16+
NSString *htmlString = ConvertURLToText((NSURL*)url);
17+
NSRect viewRect = NSMakeRect(0.0, 0.0, 800.0, 600.0);
18+
float scale = maxSize.height / 800.0;
19+
NSLog(@"scale: %f, %@", scale, NSStringFromSize(NSSizeFromCGSize(maxSize)));
20+
NSSize scaleSize = NSMakeSize(scale, scale);
21+
CGSize thumbSize = NSSizeToCGSize(NSMakeSize((maxSize.width * (600.0/800.0)),
22+
maxSize.height));
23+
24+
WebView* webView = [[WebView alloc] initWithFrame: viewRect];
25+
[webView scaleUnitSquareToSize: scaleSize];
26+
[[[webView mainFrame] frameView] setAllowsScrolling:NO];
27+
[[webView mainFrame] loadHTMLString:htmlString baseURL:nil];
28+
29+
while ([webView isLoading])
30+
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.0, true);
31+
32+
[webView display];
33+
34+
CGContextRef context =
35+
QLThumbnailRequestCreateContext(thumbnail, thumbSize, false, NULL);
36+
37+
if (context) {
38+
NSGraphicsContext* nsContext =
39+
[NSGraphicsContext
40+
graphicsContextWithGraphicsPort: (void*) context
41+
flipped: [webView isFlipped]];
42+
43+
[webView displayRectIgnoringOpacity: [webView bounds]
44+
inContext: nsContext];
45+
46+
QLThumbnailRequestFlushContext(thumbnail, context);
47+
48+
CFRelease(context);
49+
}
50+
return noErr;
51+
}
52+
53+
void CancelThumbnailGeneration(void* thisInterface, QLThumbnailRequestRef thumbnail)
54+
{
55+
// implement only if supported
56+
}

Info.plist

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>UTImportedTypeDeclarations</key>
6+
<array>
7+
<dict>
8+
<key>UTTypeIdentifier</key>
9+
<string>net.daringfireball.markdown</string>
10+
<key>UTTypeReferenceURL</key>
11+
<string>http://daringfireball.net/projects/markdown/</string>
12+
<key>UTTypeDescription</key>
13+
<string>Markdown document</string>
14+
<key>UTTypeIconFile</key>
15+
<string>public.text.icns</string>
16+
<key>UTTypeConformsTo</key>
17+
<array>
18+
<string>public.text</string>
19+
</array>
20+
<key>UTTypeTagSpecification</key>
21+
<dict>
22+
<key>public.filename-extension</key>
23+
<array>
24+
<string>markdown</string>
25+
<string>mdown</string>
26+
<string>md</string>
27+
</array>
28+
</dict>
29+
</dict>
30+
</array>
31+
<key>CFBundleDevelopmentRegion</key>
32+
<string>English</string>
33+
<key>CFBundleDocumentTypes</key>
34+
<array>
35+
<dict>
36+
<key>CFBundleTypeRole</key>
37+
<string>QLGenerator</string>
38+
<key>LSItemContentTypes</key>
39+
<array>
40+
<string>net.daringfireball.markdown</string>
41+
</array>
42+
</dict>
43+
</array>
44+
<key>CFBundleExecutable</key>
45+
<string>${EXECUTABLE_NAME}</string>
46+
<key>CFBundleIconFile</key>
47+
<string></string>
48+
<key>CFBundleIdentifier</key>
49+
<string>org.minuszero.qlgenerator.${PRODUCT_NAME:identifier}</string>
50+
<key>CFBundleInfoDictionaryVersion</key>
51+
<string>6.0</string>
52+
<key>CFBundleName</key>
53+
<string>${PRODUCT_NAME}</string>
54+
<key>CFBundleShortVersionString</key>
55+
<string>1</string>
56+
<key>CFBundleVersion</key>
57+
<string>1.0</string>
58+
<key>CFPlugInDynamicRegisterFunction</key>
59+
<string></string>
60+
<key>CFPlugInDynamicRegistration</key>
61+
<string>NO</string>
62+
<key>CFPlugInFactories</key>
63+
<dict>
64+
<key>D5390375-84E6-49BA-8AB6-6DE5E22BB93A</key>
65+
<string>QuickLookGeneratorPluginFactory</string>
66+
</dict>
67+
<key>CFPlugInTypes</key>
68+
<dict>
69+
<key>5E2D9680-5022-40FA-B806-43349622E5B9</key>
70+
<array>
71+
<string>D5390375-84E6-49BA-8AB6-6DE5E22BB93A</string>
72+
</array>
73+
</dict>
74+
<key>CFPlugInUnloadFunction</key>
75+
<string></string>
76+
<key>QLNeedsToBeRunInMainThread</key>
77+
<false/>
78+
<key>QLPreviewHeight</key>
79+
<real>600</real>
80+
<key>QLPreviewWidth</key>
81+
<real>800</real>
82+
<key>QLSupportsConcurrentRequests</key>
83+
<false/>
84+
<key>QLThumbnailMinimumSize</key>
85+
<real>17</real>
86+
</dict>
87+
</plist>

Plugin/QLMarkdown.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env python
2+
# encoding: utf-8
3+
"""
4+
QLMarkdown.py
5+
6+
Created by Dave Arter on 2009-02-04.
7+
Copyright (c) 2009 __MyCompanyName__. All rights reserved.
8+
"""
9+
import sys
10+
sys.path.append('/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/PyObjC/')
11+
12+
from Foundation import *
13+
14+
from markdown2 import markdown2
15+
16+
class QLMarkdown(NSObject):
17+
def convertText_(self, text):
18+
return markdown2.markdown(text)

Plugin/markdown2/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import markdown2

0 commit comments

Comments
 (0)