6 Commits

Author SHA1 Message Date
rentzsch 518fdfe2e6 Merge pull request #10 from vojto/markdownlive
---

Things you should know:

1. Im not using your subclasses of NSTextView/NSLayoutManager/etc. Felt like whatever it did wasnt too important. Sorry, didnt want to spend too much time integrating.

2. It highlight the whole thing whenever you press a key. Didnt try it with large documents and I would expect problems. Maybe better solution would be to highlight only current line, visible range, etc.

3. Markdown syntax is incomplete, but can be easily configured from the plist. 

Thanks!
2011-09-02 19:13:48 -05:00
Vojto Rinik be6c76831a Adding link to Lion build 2011-09-02 19:38:02 -04:00
Vojto Rinik e24a91fa08 Adding 'about fork' section 2011-09-02 19:34:40 -04:00
Vojto Rinik 1dae696cb7 adding screenshot 2011-09-02 19:24:24 -04:00
Vojto Rinik 5d5dfe5da6 Using RKSyntaxView for syntax highlighting 2011-09-02 19:20:49 -04:00
rentzsch 21f4bf11ae Merge branch 'hotfix/1.7.1' into develop 2011-07-21 21:06:54 -05:00
12 changed files with 504 additions and 41 deletions
+61 -38
View File
@@ -2,10 +2,10 @@
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.10">
<data>
<int key="IBDocument.SystemTarget">1060</int>
<string key="IBDocument.SystemVersion">10J4138</string>
<string key="IBDocument.InterfaceBuilderVersion">1306</string>
<string key="IBDocument.AppKitVersion">1038.35</string>
<string key="IBDocument.HIToolboxVersion">461.00</string>
<string key="IBDocument.SystemVersion">11B26</string>
<string key="IBDocument.InterfaceBuilderVersion">1617</string>
<string key="IBDocument.AppKitVersion">1138</string>
<string key="IBDocument.HIToolboxVersion">566.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
@@ -15,8 +15,8 @@
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>1306</string>
<string>30</string>
<string>1617</string>
<string>518</string>
</object>
</object>
<object class="NSArray" key="IBDocument.IntegratedClassDependencies">
@@ -36,8 +36,11 @@
<string>com.apple.WebKitIBPlugin</string>
</object>
<object class="NSMutableDictionary" key="IBDocument.Metadata">
<string key="NS.key.0">PluginDependencyRecalculationVersion</string>
<integer value="1" key="NS.object.0"/>
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys" id="0">
<bool key="EncodedWithXMLCoder">YES</bool>
</object>
<reference key="dict.values" ref="0"/>
</object>
<object class="NSMutableArray" key="IBDocument.RootObjects" id="580458321">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -55,6 +58,7 @@
<string key="NSWindowTitle">Window</string>
<string key="NSWindowClass">NSWindow</string>
<string key="NSViewClass">View</string>
<nil key="NSUserInterfaceItemIdentifier"/>
<string key="NSWindowContentMinSize">{94, 86}</string>
<object class="NSView" key="NSWindowView" id="568628114">
<reference key="NSNextResponder"/>
@@ -105,7 +109,7 @@
<string key="NSFrameSize">{439, 44}</string>
<reference key="NSSuperview" ref="934421653"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="497745035"/>
<reference key="NSNextKeyView" ref="106470570"/>
<object class="NSTextContainer" key="NSTextContainer" id="515139633">
<object class="NSLayoutManager" key="NSLayoutManager">
<object class="NSTextStorage" key="NSTextStorage">
@@ -126,7 +130,7 @@
<int key="NSTCFlags">1</int>
</object>
<object class="NSTextViewSharedData" key="NSSharedData">
<int key="NSFlags">12003</int>
<int key="NSFlags">67120867</int>
<int key="NSTextCheckingTypes">0</int>
<nil key="NSMarkedAttributes"/>
<object class="NSColor" key="NSBackgroundColor" id="144579518">
@@ -185,9 +189,11 @@
</object>
</object>
<nil key="NSDefaultParagraphStyle"/>
<nil key="NSTextFinder"/>
<int key="NSPreferredTextFinderStyle">1</int>
</object>
<int key="NSTVFlags">6</int>
<string key="NSMaxSize">{463, 1e+07}</string>
<string key="NSMaxSize">{463, 10000000}</string>
<string key="NSMinize">{223, 44}</string>
<nil key="NSDelegate"/>
</object>
@@ -199,8 +205,30 @@
<reference key="NSDocView" ref="521201844"/>
<reference key="NSBGColor" ref="144579518"/>
<object class="NSCursor" key="NSCursor">
<string key="NSHotSpot">{4, -5}</string>
<int key="NSCursorType">1</int>
<string key="NSHotSpot">{4, 5}</string>
<object class="NSImage" key="NSImage">
<int key="NSImageFlags">12582912</int>
<object class="NSMutableArray" key="NSReps">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray">
<bool key="EncodedWithXMLCoder">YES</bool>
<integer value="0"/>
<object class="NSBitmapImageRep">
<object class="NSData" key="NSTIFFRepresentation">
<bytes key="NS.bytes">TU0AKgAAAHCAFUqgBVKsAAAAwdVQUqwaEQeIRGJRGFlYqwWLQ+JxuOQpVRmEx2RROKwOQyOUQSPyaUym
SxqWyKXyeYxyZzWbSuJTScRCbz2Nz+gRKhUOfTqeUai0OSxiWTiBQSHSGFquGwekxyAgAAAOAQAAAwAA
AAEAEAAAAQEAAwAAAAEAEAAAAQIAAwAAAAIACAAIAQMAAwAAAAEABQAAAQYAAwAAAAEAAQAAAREABAAA
AAEAAAAIARIAAwAAAAEAAQAAARUAAwAAAAEAAgAAARYAAwAAAAEAEAAAARcABAAAAAEAAABnARwAAwAA
AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA</bytes>
</object>
</object>
</object>
</object>
<object class="NSColor" key="NSColor">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MCAwAA</bytes>
</object>
</object>
</object>
<int key="NScvFlags">4</int>
</object>
@@ -233,8 +261,8 @@
<string key="NSFrameSize">{439, 600}</string>
<reference key="NSSuperview" ref="202269651"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="934421653"/>
<int key="NSsFlags">528</int>
<reference key="NSNextKeyView" ref="497745035"/>
<int key="NSsFlags">133648</int>
<reference key="NSVScroller" ref="106470570"/>
<reference key="NSHScroller" ref="497745035"/>
<reference key="NSContentView" ref="934421653"/>
@@ -299,14 +327,15 @@
<int key="NSDividerStyle">3</int>
</object>
</object>
<string key="NSFrame">{{7, 11}, {860, 600}}</string>
<string key="NSFrameSize">{860, 600}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="202269651"/>
</object>
<string key="NSScreenRect">{{0, 0}, {1680, 1028}}</string>
<string key="NSScreenRect">{{0, 0}, {1440, 878}}</string>
<string key="NSMinSize">{94, 108}</string>
<string key="NSMaxSize">{1e+13, 1e+13}</string>
<string key="NSMaxSize">{10000000000000, 10000000000000}</string>
<bool key="NSWindowIsRestorable">YES</bool>
</object>
<object class="NSCustomObject" id="796877042">
<string key="NSClassName">NSApplication</string>
@@ -377,9 +406,7 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBObjectRecord">
<int key="objectID">0</int>
<object class="NSArray" key="object" id="0">
<bool key="EncodedWithXMLCoder">YES</bool>
</object>
<reference key="object" ref="0"/>
<reference key="children" ref="580458321"/>
<nil key="parent"/>
</object>
@@ -467,6 +494,8 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>-1.IBPluginDependency</string>
<string>-2.IBPluginDependency</string>
<string>-3.IBPluginDependency</string>
<string>100021.IBPluginDependency</string>
<string>100022.IBPluginDependency</string>
@@ -475,14 +504,10 @@
<string>100024.IBPluginDependency</string>
<string>100025.IBPluginDependency</string>
<string>100026.IBPluginDependency</string>
<string>5.IBEditorWindowLastContentRect</string>
<string>5.IBPluginDependency</string>
<string>5.IBWindowTemplateEditedContentRect</string>
<string>5.ImportedFromIB2</string>
<string>5.NSWindowTemplate.visibleAtLaunch</string>
<string>5.editorWindowContentRectSynchronizationRect</string>
<string>6.IBPluginDependency</string>
<string>6.ImportedFromIB2</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -490,18 +515,16 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>EditPaneTextView</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>RKSyntaxView</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.WebKitIBPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>{{597, 57}, {769, 667}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>{{597, 57}, {769, 667}}</string>
<integer value="1"/>
<boolean value="NO"/>
<string>{{201, 387}, {507, 413}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<integer value="1"/>
</object>
</object>
<object class="NSMutableDictionary" key="unlocalizedProperties">
@@ -521,14 +544,6 @@
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBPartialClassDescription">
<string key="className">EditPaneTextView</string>
<string key="superclassName">NSTextView</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/EditPaneTextView.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">MyDocument</string>
<string key="superclassName">NSDocument</string>
@@ -647,6 +662,14 @@
<string key="minorKey">./Classes/NSDocument.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">RKSyntaxView</string>
<string key="superclassName">NSTextView</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/RKSyntaxView.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">WebView</string>
<object class="NSMutableDictionary" key="actions">
+32
View File
@@ -16,6 +16,10 @@
8D15AC310486D014006FF6A4 /* MyDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = 2A37F4ACFDCFA73011CA2CEA /* MyDocument.m */; settings = {ATTRIBUTES = (); }; };
8D15AC320486D014006FF6A4 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 2A37F4B0FDCFA73011CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
8D15AC340486D014006FF6A4 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A7FEA54F5311CA2CBB /* Cocoa.framework */; };
9958D88F14119A22004F7DF1 /* RKSyntaxView.m in Sources */ = {isa = PBXBuildFile; fileRef = 9958D88E14119A22004F7DF1 /* RKSyntaxView.m */; };
9958D89214119A8D004F7DF1 /* NSColor+HexRGB.m in Sources */ = {isa = PBXBuildFile; fileRef = 9958D89114119A8D004F7DF1 /* NSColor+HexRGB.m */; };
9958D89514119B85004F7DF1 /* PageScheme.plist in Resources */ = {isa = PBXBuildFile; fileRef = 9958D89314119B85004F7DF1 /* PageScheme.plist */; };
9958D89614119B85004F7DF1 /* PageSyntax.plist in Resources */ = {isa = PBXBuildFile; fileRef = 9958D89414119B85004F7DF1 /* PageSyntax.plist */; };
ABE8DDF913CA38B5005852B5 /* styles.css in Resources */ = {isa = PBXBuildFile; fileRef = 226936E612E7CDC500171322 /* styles.css */; };
ABECD8C713C8B90E00B77CFD /* mkdio.c in Sources */ = {isa = PBXBuildFile; fileRef = 795F6C4E105D6EC400D1F90A /* mkdio.c */; };
ABECD8C813C8B92900B77CFD /* markdown.c in Sources */ = {isa = PBXBuildFile; fileRef = 795F6C50105D6ECE00D1F90A /* markdown.c */; };
@@ -107,6 +111,12 @@
795F6DB9105D75D300D1F90A /* mkdioWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mkdioWrapper.h; sourceTree = "<group>"; };
8D15AC360486D014006FF6A4 /* MarkdownLive-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "MarkdownLive-Info.plist"; sourceTree = "<group>"; };
8D15AC370486D014006FF6A4 /* MarkdownLive.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MarkdownLive.app; sourceTree = BUILT_PRODUCTS_DIR; };
9958D88D14119A22004F7DF1 /* RKSyntaxView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RKSyntaxView.h; sourceTree = "<group>"; };
9958D88E14119A22004F7DF1 /* RKSyntaxView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKSyntaxView.m; sourceTree = "<group>"; };
9958D89014119A8D004F7DF1 /* NSColor+HexRGB.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSColor+HexRGB.h"; sourceTree = "<group>"; };
9958D89114119A8D004F7DF1 /* NSColor+HexRGB.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSColor+HexRGB.m"; sourceTree = "<group>"; };
9958D89314119B85004F7DF1 /* PageScheme.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = PageScheme.plist; sourceTree = "<group>"; };
9958D89414119B85004F7DF1 /* PageSyntax.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = PageSyntax.plist; sourceTree = "<group>"; };
ABCE3DDF13C8DFFF00DF3CD0 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.md; sourceTree = "<group>"; };
ABECD8C213C8B8CA00B77CFD /* ORCDiscount.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ORCDiscount.framework; sourceTree = BUILT_PRODUCTS_DIR; };
ABECD8C313C8B8CA00B77CFD /* ORCDiscount-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "ORCDiscount-Info.plist"; sourceTree = "<group>"; };
@@ -180,6 +190,7 @@
2A37F4AAFDCFA73011CA2CEA /* MarkdownLive */ = {
isa = PBXGroup;
children = (
9958D88B14119A18004F7DF1 /* RK */,
ABECD96113C8D1C200B77CFD /* ORCDiscount */,
2A37F4ABFDCFA73011CA2CEA /* Classes */,
795F6C4D105D6EA500D1F90A /* discount */,
@@ -228,6 +239,8 @@
089C165FFE840EACC02AAC07 /* InfoPlist.strings */,
1DDD58280DA1D0D100B32029 /* MyDocument.xib */,
1DDD582A0DA1D0D100B32029 /* MainMenu.xib */,
9958D89314119B85004F7DF1 /* PageScheme.plist */,
9958D89414119B85004F7DF1 /* PageSyntax.plist */,
);
name = Resources;
sourceTree = "<group>";
@@ -273,6 +286,17 @@
path = discount_wrappers;
sourceTree = "<group>";
};
9958D88B14119A18004F7DF1 /* RK */ = {
isa = PBXGroup;
children = (
9958D89014119A8D004F7DF1 /* NSColor+HexRGB.h */,
9958D89114119A8D004F7DF1 /* NSColor+HexRGB.m */,
9958D88D14119A22004F7DF1 /* RKSyntaxView.h */,
9958D88E14119A22004F7DF1 /* RKSyntaxView.m */,
);
name = RK;
sourceTree = "<group>";
};
ABECD96113C8D1C200B77CFD /* ORCDiscount */ = {
isa = PBXGroup;
children = (
@@ -373,6 +397,8 @@
1DDD582C0DA1D0D100B32029 /* MyDocument.xib in Resources */,
1DDD582D0DA1D0D100B32029 /* MainMenu.xib in Resources */,
795F6C87105D70A300D1F90A /* MarkdownLiveApp.icns in Resources */,
9958D89514119B85004F7DF1 /* PageScheme.plist in Resources */,
9958D89614119B85004F7DF1 /* PageSyntax.plist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -398,6 +424,8 @@
ABF75D7513CDEBBB00B5E7AB /* EditPaneTypesetter.m in Sources */,
ABF75D7613CDEBBB00B5E7AB /* PreferencesController.m in Sources */,
ABF75D7713CDEBBB00B5E7AB /* PreferencesManager.m in Sources */,
9958D88F14119A22004F7DF1 /* RKSyntaxView.m in Sources */,
9958D89214119A8D004F7DF1 /* NSColor+HexRGB.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -538,7 +566,9 @@
GCC_PREFIX_HEADER = MarkdownLive_Prefix.pch;
INFOPLIST_FILE = "MarkdownLive-Info.plist";
INSTALL_PATH = "$(HOME)/Applications";
MACOSX_DEPLOYMENT_TARGET = 10.7;
PRODUCT_NAME = MarkdownLive;
SDKROOT = macosx;
};
name = Debug;
};
@@ -553,7 +583,9 @@
GCC_PREFIX_HEADER = MarkdownLive_Prefix.pch;
INFOPLIST_FILE = "MarkdownLive-Info.plist";
INSTALL_PATH = "$(HOME)/Applications";
MACOSX_DEPLOYMENT_TARGET = 10.7;
PRODUCT_NAME = MarkdownLive;
SDKROOT = macosx;
};
name = Release;
};
+2 -1
View File
@@ -7,12 +7,13 @@
#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>
#import "RKSyntaxView.h"
@class EditPaneTextView;
@class EditPaneLayoutManager;
@interface MyDocument : NSDocument {
IBOutlet EditPaneTextView *markdownSourceTextView;
IBOutlet RKSyntaxView *markdownSourceTextView;
IBOutlet WebView *htmlPreviewWebView;
NSTextStorage *markdownSource;
+6 -2
View File
@@ -72,8 +72,12 @@ NSString *kMarkdownDocumentType = @"MarkdownDocumentType";
// If you use IB to set an NSTextView's font, the font doesn't stick,
// even if you've turned off the text view's richText setting.
[markdownSourceTextView updateFont];
[markdownSourceTextView updateColors];
//[markdownSourceTextView updateFont];
//[markdownSourceTextView updateColors];
[markdownSourceTextView loadScheme:@"PageScheme"];
[markdownSourceTextView loadSyntax:@"PageSyntax"];
[markdownSourceTextView highlight];
[super windowControllerDidLoadNib:controller_];
}
+16
View File
@@ -0,0 +1,16 @@
//
// NSColor+HexRGB.h
// TextDo
//
// Created by Vojto Rinik on 28.6.2011.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSColor (NSColor_HexRGB)
+ (NSColor *) colorFromHexRGB:(NSString *) inColorString;
@end
+35
View File
@@ -0,0 +1,35 @@
//
// NSColor+HexRGB.m
// TextDo
//
// Created by Vojto Rinik on 28.6.2011.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "NSColor+HexRGB.h"
@implementation NSColor (NSColor_HexRGB)
+ (NSColor *) colorFromHexRGB:(NSString *) inColorString {
NSColor *result = nil;
unsigned int colorCode = 0;
unsigned char redByte, greenByte, blueByte;
if (nil != inColorString)
{
NSScanner *scanner = [NSScanner scannerWithString:inColorString];
(void) [scanner scanHexInt:&colorCode]; // ignore error
}
redByte = (unsigned char) (colorCode >> 16);
greenByte = (unsigned char) (colorCode >> 8);
blueByte = (unsigned char) (colorCode); // masks off high bits
result = [NSColor
colorWithCalibratedRed: (float)redByte / 0xff
green: (float)greenByte/ 0xff
blue: (float)blueByte / 0xff
alpha:1.0];
return result;
}
@end
+35
View File
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>colors</key>
<dict>
<key>title3</key>
<string>6C71C4</string>
<key>em</key>
<string>859900</string>
<key>strong</key>
<string>48595f</string>
<key>code</key>
<string>2AA198</string>
<key>codeBackground</key>
<string>EEE8D5</string>
<key>highlight</key>
<string>EEE8D5</string>
<key>background</key>
<string>FDF6E3</string>
<key>checked</key>
<string>8e8e8e</string>
<key>default</key>
<string>586E75</string>
<key>subtitle</key>
<string>268BD2</string>
<key>title</key>
<string>DC322F</string>
<key>zone</key>
<string>f21bea</string>
</dict>
<key>font</key>
<string>Menlo</string>
</dict>
</plist>
+92
View File
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>todo-zone</key>
<dict>
<key>color</key>
<string>zone</string>
<key>pattern</key>
<string>^●\s*.*$</string>
</dict>
<key>todo-checked</key>
<dict>
<key>color</key>
<string>checked</string>
<key>pattern</key>
<string>^✓\s*.*$</string>
</dict>
<key>todo-unchecked</key>
<dict>
<key>color</key>
<string>default</string>
<key>pattern</key>
<string>^☐\s*.*$</string>
</dict>
<key>list-item</key>
<dict>
<key>color</key>
<string>default</string>
<key>pattern</key>
<string>^\*\s+.*$</string>
</dict>
<key>markdown-header-1</key>
<dict>
<key>size</key>
<integer>14</integer>
<key>isBold</key>
<true/>
<key>color</key>
<string>title</string>
<key>pattern</key>
<string>^(# )(.*?)($| #+$)</string>
</dict>
<key>markdown-header-2</key>
<dict>
<key>color</key>
<string>subtitle</string>
<key>isBold</key>
<true/>
<key>pattern</key>
<string>^(## )(.*?)($| #+$)</string>
</dict>
<key>markdown-em</key>
<dict>
<key>color</key>
<string>em</string>
<key>patternGroup</key>
<integer>2</integer>
<key>pattern</key>
<string>(^|[^\*])(\*[^\s\*]([^\*\n]+)\*)</string>
</dict>
<key>markdown-strong</key>
<dict>
<key>isBold</key>
<true/>
<key>color</key>
<string>strong</string>
<key>pattern</key>
<string>\*{2}(.+?)\*{2}</string>
</dict>
<key>markdown-header-3</key>
<dict>
<key>color</key>
<string>title3</string>
<key>isBold</key>
<true/>
<key>pattern</key>
<string>^(### )(.*?)($| #+$)</string>
</dict>
<key>code</key>
<dict>
<key>patternGroup</key>
<integer>1</integer>
<key>backgroundColor</key>
<string>codeBackground</string>
<key>color</key>
<string>code</string>
<key>pattern</key>
<string>^ {4}(.*?)$</string>
</dict>
</dict>
</plist>
+11
View File
@@ -1,3 +1,14 @@
## About my fork
Adds beautiful syntax highlighting to MarkdownLive.
![screenshot](https://github.com/vojto/markdownlive/raw/master/sshot.png)
[Grab Lion build](https://github.com/downloads/vojto/markdownlive/MarkdownLive.zip)
Like it? Buy [one of my apps](http://rinik.net/apps).
## MarkdownLive
A Cocoa markdown preview editor using [Discount][discount].
+45
View File
@@ -0,0 +1,45 @@
//
// RKSyntaxView.h
//
//
// Created by Vojto Rinik on 8/24/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
@interface RKSyntaxView : NSTextView {
NSDictionary *_scheme;
NSDictionary *_syntax;
NSMutableAttributedString *_content;
}
@property (retain) NSDictionary *scheme;
@property (retain) NSDictionary *syntax;
@property (retain) NSMutableAttributedString *content;
- (void) _setup;
#pragma mark - Handling text change
- (void) _textDidChange:(NSNotification *)notif;
#pragma mark - Highlighting
- (void) highlight;
- (void) highlightRange:(NSRange)range;
#pragma mark - Scheme
- (void) loadScheme:(NSString *)schemeFilename;
- (NSColor *) _colorFor:(NSString *)key;
- (NSFont *) _font;
- (NSFont *) _fontOfSize:(NSInteger)size bold:(BOOL)wantsBold;
#pragma mark - Syntax
- (void) loadSyntax:(NSString *)syntaxFilename;
#pragma mark - Changing text attributes
- (void) _setTextColor:(NSColor *)color range:(NSRange)range;
- (void) _setBackgroundColor:(NSColor *)color range:(NSRange)range;
- (void) _setFont:(NSFont *)font range:(NSRange)range;
- (void) _reflect;
@end
+169
View File
@@ -0,0 +1,169 @@
//
// RKSyntaxView.m
//
//
// Created by Vojto Rinik on 8/24/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "RKSyntaxView.h"
#import "NSColor+HexRGB.h"
@implementation RKSyntaxView
@synthesize scheme=_scheme;
@synthesize syntax=_syntax;
@synthesize content=_content;
#pragma mark - Lifecycle
- (id)init {
if ((self = [super init])) {
[self _setup];
}
return self;
}
- (void)awakeFromNib {
[self _setup];
}
- (void)_setup {
self.content = [[[NSMutableAttributedString alloc] init] autorelease];
[self setTextContainerInset:NSMakeSize(10.0, 10.0)];
[self highlight];
[self addObserver:self forKeyPath:@"string" options:0 context:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_textDidChange:) name:NSTextDidChangeNotification object:self];
}
- (void) dealloc {
self.content = nil;
[super dealloc];
}
#pragma mark - Handling text changes
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
[self highlight];
}
- (void)_textDidChange:(NSNotification *)notif {
[self highlight];
}
#pragma mark - Scheme
- (void)loadScheme:(NSString *)schemeFilename {
NSString *schemePath = [[NSBundle mainBundle] pathForResource:schemeFilename ofType:@"plist" inDirectory:nil];
self.scheme = [NSDictionary dictionaryWithContentsOfFile:schemePath];
}
- (NSColor *) _colorFor:(NSString *)key {
NSString *colorCode = [[self.scheme objectForKey:@"colors"] objectForKey:key];
if (!colorCode) return nil;
NSColor *color = [NSColor colorFromHexRGB:colorCode];
return color;
}
- (NSFont *) _font {
return [self _fontOfSize:12 bold:NO];
}
- (NSFont *) _fontOfSize:(NSInteger)size bold:(BOOL)wantsBold {
NSString *fontName = [self.scheme objectForKey:@"font"];
NSFont *font = [NSFont fontWithName:fontName size:size];
if (!font) font = [NSFont systemFontOfSize:size];
if (wantsBold) {
NSFontTraitMask traits = NSBoldFontMask;
NSFontManager *manager = [NSFontManager sharedFontManager];
font = [manager fontWithFamily:fontName traits:traits weight:5.0 size:size];
}
return font;
}
#pragma mark - Syntax
- (void)loadSyntax:(NSString *)syntaxFilename {
NSString *schemePath = [[NSBundle mainBundle] pathForResource:syntaxFilename ofType:@"plist" inDirectory:nil];
self.syntax = [NSDictionary dictionaryWithContentsOfFile:schemePath];
}
#pragma mark - Highlighting
- (void) highlight {
self.content = [[NSMutableAttributedString alloc] initWithString:[self string]];
[self.content release];
NSColor *background = [self _colorFor:@"background"];
[self setBackgroundColor:background];
[(NSScrollView *)self.superview setBackgroundColor:background];
[self setTextColor:[self _colorFor:@"default"]];
return [self highlightRange:NSMakeRange(0, [self.content length])];
}
- (void) highlightRange:(NSRange)range {
NSColor *defaultColor = [self _colorFor:@"default"];
NSInteger defaultSize = [(NSNumber *)[self.scheme objectForKey:@"size"] integerValue];
if (!defaultSize) defaultSize = 12;
NSFont *defaultFont = [self _fontOfSize:defaultSize bold:NO];
[self _setFont:defaultFont range:range];
[self _setTextColor:defaultColor range:range];
[self _setBackgroundColor:[NSColor clearColor] range:range];
NSString *string = [self.content string];
for (NSString *type in [self.syntax allKeys]) {
NSDictionary *params = [self.syntax objectForKey:type];
NSString *pattern = [params objectForKey:@"pattern"];
NSString *colorName = [params objectForKey:@"color"];
NSColor *color = [self _colorFor:colorName];
NSString *backgroundColorName = [params objectForKey:@"backgroundColor"];
NSColor *backgroundColor = [self _colorFor:backgroundColorName];
NSInteger size = [(NSNumber *)[params objectForKey:@"size"] integerValue];
BOOL isBold = [(NSNumber *)[params objectForKey:@"isBold"] boolValue];
NSFont *font = [self _fontOfSize:(size?size:defaultSize) bold:isBold];
NSInteger patternGroup = [(NSNumber *)[params objectForKey:@"patternGroup"] integerValue];
NSError *error = nil;
NSRegularExpression *expr = [NSRegularExpression regularExpressionWithPattern:pattern options:NSRegularExpressionCaseInsensitive|NSRegularExpressionAnchorsMatchLines error:&error];
NSArray *matches = [expr matchesInString:string options:0 range:range];
for (NSTextCheckingResult *match in matches) {
NSRange range = patternGroup ? [match rangeAtIndex:patternGroup] : [match range];
[self _setTextColor:color range:range];
if (backgroundColor) [self _setBackgroundColor:backgroundColor range:range];
[self _setFont:font range:range];
}
}
[self _reflect];
}
#pragma mark - Changing text attributes
- (void) _setTextColor:(NSColor *)color range:(NSRange)range {
if (!color) return;
[self.content addAttribute:NSForegroundColorAttributeName value:color range:range];
}
- (void) _setBackgroundColor:(NSColor *)color range:(NSRange)range {
[self.content addAttribute:NSBackgroundColorAttributeName value:color range:range];
}
- (void) _setFont:(NSFont *)font range:(NSRange)range {
[self.content addAttribute:NSFontAttributeName value:font range:range];
}
- (void) _reflect {
NSTextStorage *storage = [self textStorage];
NSAttributedString *content = self.content;
NSRange range = NSMakeRange(0, [content length]);
[content enumerateAttributesInRange:range options:0 usingBlock:^(NSDictionary *attributes, NSRange range, BOOL *stop){
[storage setAttributes:attributes range:range];
}];
}
@end
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 178 KiB