Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e86d87a

Browse filesBrowse files
silumanthonygelibert
authored andcommitted
GeneratePreviewForURL.m: add RTF conversion
1 parent 7f7ba22 commit e86d87a
Copy full SHA for e86d87a

File tree

Expand file treeCollapse file tree

2 files changed

+25
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+25
-4
lines changed
Open diff view settings
Collapse file

‎README.md‎

Copy file name to clipboardExpand all lines: README.md
+6Lines changed: 6 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ Here are some useful 'highlight' command-line flags (from the man page):
8282

8383
defaults write org.n8gray.QLColorCode pathHL /path/to/your/highlight
8484

85+
It is also possible to have the HTML preview converted to RTF. Using RTF
86+
allows the contents of the file to be displayed instead of an icon -- similar
87+
to QLStephen.
88+
89+
defaults write org.n8gray.QLColorCode rtfRender true
90+
8591
## Additional information
8692

8793
### Additional features
Collapse file

‎src/GeneratePreviewForURL.m‎

Copy file name to clipboardExpand all lines: src/GeneratePreviewForURL.m
+19-4Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#import <CoreServices/CoreServices.h>
66
#import <Foundation/Foundation.h>
77
#import <QuickLook/QuickLook.h>
8+
#import <AppKit/AppKit.h>
89
#import "Common.h"
910

1011

@@ -34,6 +35,19 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
3435
n8log(@"Generated preview html page in %.3f sec",
3536
-[startDate timeIntervalSinceNow] );
3637

38+
NSData *rtf = nil;
39+
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:myDomain];
40+
BOOL use_rtf = [defaults boolForKey:@"rtfPreview"];
41+
[defaults release];
42+
43+
if (use_rtf) {
44+
NSDictionary *attrs;
45+
NSAttributedString *string = [[NSAttributedString alloc] initWithHTML:output documentAttributes:&attrs];
46+
NSRange range = NSMakeRange(0, [string length]);
47+
rtf = [string RTFFromRange:range documentAttributes:attrs];
48+
[string release];
49+
}
50+
3751
if (status != 0 || QLPreviewRequestIsCancelled(preview)) {
3852
#ifndef DEBUG
3953
goto done;
@@ -47,10 +61,11 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
4761
CFDictionaryRef properties =
4862
(CFDictionaryRef)[NSDictionary dictionaryWithObject:textEncoding
4963
forKey:(NSString *)kQLPreviewPropertyTextEncodingNameKey];
50-
QLPreviewRequestSetDataRepresentation(preview, (CFDataRef)output,
51-
//kUTTypePlainText,
52-
kUTTypeHTML,
53-
properties);
64+
65+
if (use_rtf)
66+
QLPreviewRequestSetDataRepresentation(preview, (CFDataRef)rtf, kUTTypeRTF, properties);
67+
else
68+
QLPreviewRequestSetDataRepresentation(preview, (CFDataRef)output, kUTTypeHTML, properties);
5469

5570
#ifndef DEBUG
5671
done:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.