mirror of
https://github.com/HackPlan/MarkdownTextView.git
synced 2026-01-12 22:48:40 +08:00
Add example app, README, LICENSE
This commit is contained in:
46
Example/AppDelegate.swift
Normal file
46
Example/AppDelegate.swift
Normal file
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// AppDelegate.swift
|
||||
// Example
|
||||
//
|
||||
// Created by Indragie on 4/29/15.
|
||||
// Copyright (c) 2015 Indragie Karunaratne. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
@UIApplicationMain
|
||||
class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
var window: UIWindow?
|
||||
|
||||
|
||||
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
|
||||
// Override point for customization after application launch.
|
||||
return true
|
||||
}
|
||||
|
||||
func applicationWillResignActive(application: UIApplication) {
|
||||
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
||||
}
|
||||
|
||||
func applicationDidEnterBackground(application: UIApplication) {
|
||||
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
|
||||
}
|
||||
|
||||
func applicationWillEnterForeground(application: UIApplication) {
|
||||
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
|
||||
}
|
||||
|
||||
func applicationDidBecomeActive(application: UIApplication) {
|
||||
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||
}
|
||||
|
||||
func applicationWillTerminate(application: UIApplication) {
|
||||
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
41
Example/Base.lproj/LaunchScreen.xib
Normal file
41
Example/Base.lproj/LaunchScreen.xib
Normal file
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6214" systemVersion="14A314h" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6207"/>
|
||||
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
|
||||
<view contentMode="scaleToFill" id="iN0-l3-epB">
|
||||
<rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2015 Indragie Karunaratne. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
|
||||
<rect key="frame" x="20" y="439" width="441" height="21"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Example" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX">
|
||||
<rect key="frame" x="20" y="140" width="441" height="43"/>
|
||||
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
|
||||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
|
||||
<constraints>
|
||||
<constraint firstItem="kId-c2-rCX" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="bottom" multiplier="1/3" constant="1" id="5cJ-9S-tgC"/>
|
||||
<constraint firstAttribute="centerX" secondItem="kId-c2-rCX" secondAttribute="centerX" id="Koa-jz-hwk"/>
|
||||
<constraint firstAttribute="bottom" secondItem="8ie-xW-0ye" secondAttribute="bottom" constant="20" id="Kzo-t9-V3l"/>
|
||||
<constraint firstItem="8ie-xW-0ye" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="MfP-vx-nX0"/>
|
||||
<constraint firstAttribute="centerX" secondItem="8ie-xW-0ye" secondAttribute="centerX" id="ZEH-qu-HZ9"/>
|
||||
<constraint firstItem="kId-c2-rCX" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="fvb-Df-36g"/>
|
||||
</constraints>
|
||||
<nil key="simulatedStatusBarMetrics"/>
|
||||
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
|
||||
<point key="canvasLocation" x="548" y="455"/>
|
||||
</view>
|
||||
</objects>
|
||||
</document>
|
||||
25
Example/Base.lproj/Main.storyboard
Normal file
25
Example/Base.lproj/Main.storyboard
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6211" systemVersion="14A298i" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6204"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--View Controller-->
|
||||
<scene sceneID="ufC-wZ-h7g">
|
||||
<objects>
|
||||
<viewController id="vXZ-lx-hvc" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<layoutGuides>
|
||||
<viewControllerLayoutGuide type="top" id="jyV-Pf-zRb"/>
|
||||
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
|
||||
</layoutGuides>
|
||||
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
|
||||
</view>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
</scene>
|
||||
</scenes>
|
||||
</document>
|
||||
38
Example/Images.xcassets/AppIcon.appiconset/Contents.json
Normal file
38
Example/Images.xcassets/AppIcon.appiconset/Contents.json
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "29x29",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "29x29",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "40x40",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "40x40",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "60x60",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "60x60",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
40
Example/Info.plist
Normal file
40
Example/Info.plist
Normal file
@@ -0,0 +1,40 @@
|
||||
<?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>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.indragie.$(PRODUCT_NAME:rfc1034identifier)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>UIMainStoryboardFile</key>
|
||||
<string>Main</string>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<array>
|
||||
<string>armv7</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
39
Example/ViewController.swift
Normal file
39
Example/ViewController.swift
Normal file
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// ViewController.swift
|
||||
// MarkdownTextView
|
||||
//
|
||||
// Created by Indragie on 4/27/15.
|
||||
// Copyright (c) 2015 Indragie Karunaratne. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import MarkdownTextView
|
||||
|
||||
class ViewController: UIViewController {
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
let attributes = MarkdownAttributes()
|
||||
let textStorage = MarkdownTextStorage(attributes: attributes)
|
||||
var error: NSError?
|
||||
if let linkHighlighter = LinkHighlighter(errorPtr: &error) {
|
||||
textStorage.addHighlighter(linkHighlighter)
|
||||
} else {
|
||||
assertionFailure("Error initializing LinkHighlighter: \(error)")
|
||||
}
|
||||
textStorage.addHighlighter(MarkdownStrikethroughHighlighter())
|
||||
textStorage.addHighlighter(MarkdownSuperscriptHighlighter())
|
||||
if let codeBlockAttributes = attributes.codeBlockAttributes {
|
||||
textStorage.addHighlighter(MarkdownFencedCodeHighlighter(attributes: codeBlockAttributes))
|
||||
}
|
||||
|
||||
let textView = MarkdownTextView(frame: CGRectZero, textStorage: textStorage)
|
||||
textView.setTranslatesAutoresizingMaskIntoConstraints(false)
|
||||
view.addSubview(textView)
|
||||
|
||||
let views = ["textView": textView]
|
||||
var constraints = NSLayoutConstraint.constraintsWithVisualFormat("V:|-20-[textView]-20-|", options: nil, metrics: nil, views: views)
|
||||
constraints += NSLayoutConstraint.constraintsWithVisualFormat("H:|-20-[textView]-20-|", options: nil, metrics: nil, views: views)
|
||||
NSLayoutConstraint.activateConstraints(constraints)
|
||||
}
|
||||
}
|
||||
19
LICENSE
Normal file
19
LICENSE
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2014 Indragie Karunaratne
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
@@ -24,6 +24,13 @@
|
||||
7252E0621AF1BCD1006D0535 /* MarkdownTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7252E0541AF1BCD0006D0535 /* MarkdownTextView.swift */; };
|
||||
7252E0631AF1BCD1006D0535 /* RegularExpressionHighlighter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7252E0551AF1BCD0006D0535 /* RegularExpressionHighlighter.swift */; };
|
||||
7252E0641AF1BCD1006D0535 /* TextUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7252E0561AF1BCD0006D0535 /* TextUtilities.swift */; };
|
||||
7252E06E1AF1BD61006D0535 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7252E06D1AF1BD61006D0535 /* AppDelegate.swift */; };
|
||||
7252E0701AF1BD61006D0535 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7252E06F1AF1BD61006D0535 /* ViewController.swift */; };
|
||||
7252E0731AF1BD61006D0535 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7252E0711AF1BD61006D0535 /* Main.storyboard */; };
|
||||
7252E0751AF1BD61006D0535 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7252E0741AF1BD61006D0535 /* Images.xcassets */; };
|
||||
7252E0781AF1BD61006D0535 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7252E0761AF1BD61006D0535 /* LaunchScreen.xib */; };
|
||||
7252E08D1AF1BD86006D0535 /* MarkdownTextView.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7252E02D1AF1BC1D006D0535 /* MarkdownTextView.framework */; };
|
||||
7252E08F1AF1BD93006D0535 /* MarkdownTextView.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = 7252E02D1AF1BC1D006D0535 /* MarkdownTextView.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
@@ -34,8 +41,29 @@
|
||||
remoteGlobalIDString = 7252E02C1AF1BC1D006D0535;
|
||||
remoteInfo = MarkdownTextView;
|
||||
};
|
||||
7252E08B1AF1BD82006D0535 /* PBXContainerItemProxy */ = {
|
||||
isa = PBXContainerItemProxy;
|
||||
containerPortal = 7252E0241AF1BC1D006D0535 /* Project object */;
|
||||
proxyType = 1;
|
||||
remoteGlobalIDString = 7252E02C1AF1BC1D006D0535;
|
||||
remoteInfo = MarkdownTextView;
|
||||
};
|
||||
/* End PBXContainerItemProxy section */
|
||||
|
||||
/* Begin PBXCopyFilesBuildPhase section */
|
||||
7252E08E1AF1BD88006D0535 /* Copy Frameworks */ = {
|
||||
isa = PBXCopyFilesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
dstPath = "";
|
||||
dstSubfolderSpec = 10;
|
||||
files = (
|
||||
7252E08F1AF1BD93006D0535 /* MarkdownTextView.framework in Copy Frameworks */,
|
||||
);
|
||||
name = "Copy Frameworks";
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
7252E02D1AF1BC1D006D0535 /* MarkdownTextView.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MarkdownTextView.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
7252E0311AF1BC1D006D0535 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
@@ -57,6 +85,13 @@
|
||||
7252E0541AF1BCD0006D0535 /* MarkdownTextView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MarkdownTextView.swift; sourceTree = "<group>"; };
|
||||
7252E0551AF1BCD0006D0535 /* RegularExpressionHighlighter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RegularExpressionHighlighter.swift; sourceTree = "<group>"; };
|
||||
7252E0561AF1BCD0006D0535 /* TextUtilities.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextUtilities.swift; sourceTree = "<group>"; };
|
||||
7252E0691AF1BD61006D0535 /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
7252E06C1AF1BD61006D0535 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
7252E06D1AF1BD61006D0535 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
7252E06F1AF1BD61006D0535 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
|
||||
7252E0721AF1BD61006D0535 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
|
||||
7252E0741AF1BD61006D0535 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
|
||||
7252E0771AF1BD61006D0535 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@@ -75,6 +110,14 @@
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
7252E0661AF1BD61006D0535 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
7252E08D1AF1BD86006D0535 /* MarkdownTextView.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
@@ -83,6 +126,7 @@
|
||||
children = (
|
||||
7252E02F1AF1BC1D006D0535 /* MarkdownTextView */,
|
||||
7252E03C1AF1BC1E006D0535 /* MarkdownTextViewTests */,
|
||||
7252E06A1AF1BD61006D0535 /* Example */,
|
||||
7252E02E1AF1BC1D006D0535 /* Products */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
@@ -92,6 +136,7 @@
|
||||
children = (
|
||||
7252E02D1AF1BC1D006D0535 /* MarkdownTextView.framework */,
|
||||
7252E0381AF1BC1E006D0535 /* MarkdownTextViewTests.xctest */,
|
||||
7252E0691AF1BD61006D0535 /* Example.app */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
@@ -144,6 +189,27 @@
|
||||
name = "Supporting Files";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
7252E06A1AF1BD61006D0535 /* Example */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
7252E06D1AF1BD61006D0535 /* AppDelegate.swift */,
|
||||
7252E06F1AF1BD61006D0535 /* ViewController.swift */,
|
||||
7252E0711AF1BD61006D0535 /* Main.storyboard */,
|
||||
7252E0741AF1BD61006D0535 /* Images.xcassets */,
|
||||
7252E0761AF1BD61006D0535 /* LaunchScreen.xib */,
|
||||
7252E06B1AF1BD61006D0535 /* Supporting Files */,
|
||||
);
|
||||
path = Example;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
7252E06B1AF1BD61006D0535 /* Supporting Files */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
7252E06C1AF1BD61006D0535 /* Info.plist */,
|
||||
);
|
||||
name = "Supporting Files";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXHeadersBuildPhase section */
|
||||
@@ -194,6 +260,25 @@
|
||||
productReference = 7252E0381AF1BC1E006D0535 /* MarkdownTextViewTests.xctest */;
|
||||
productType = "com.apple.product-type.bundle.unit-test";
|
||||
};
|
||||
7252E0681AF1BD61006D0535 /* Example */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 7252E0851AF1BD61006D0535 /* Build configuration list for PBXNativeTarget "Example" */;
|
||||
buildPhases = (
|
||||
7252E0651AF1BD61006D0535 /* Sources */,
|
||||
7252E0661AF1BD61006D0535 /* Frameworks */,
|
||||
7252E0671AF1BD61006D0535 /* Resources */,
|
||||
7252E08E1AF1BD88006D0535 /* Copy Frameworks */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
7252E08C1AF1BD82006D0535 /* PBXTargetDependency */,
|
||||
);
|
||||
name = Example;
|
||||
productName = Example;
|
||||
productReference = 7252E0691AF1BD61006D0535 /* Example.app */;
|
||||
productType = "com.apple.product-type.application";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
@@ -209,6 +294,9 @@
|
||||
7252E0371AF1BC1E006D0535 = {
|
||||
CreatedOnToolsVersion = 6.3.1;
|
||||
};
|
||||
7252E0681AF1BD61006D0535 = {
|
||||
CreatedOnToolsVersion = 6.3.1;
|
||||
};
|
||||
};
|
||||
};
|
||||
buildConfigurationList = 7252E0271AF1BC1D006D0535 /* Build configuration list for PBXProject "MarkdownTextView" */;
|
||||
@@ -217,6 +305,7 @@
|
||||
hasScannedForEncodings = 0;
|
||||
knownRegions = (
|
||||
en,
|
||||
Base,
|
||||
);
|
||||
mainGroup = 7252E0231AF1BC1D006D0535;
|
||||
productRefGroup = 7252E02E1AF1BC1D006D0535 /* Products */;
|
||||
@@ -225,6 +314,7 @@
|
||||
targets = (
|
||||
7252E02C1AF1BC1D006D0535 /* MarkdownTextView */,
|
||||
7252E0371AF1BC1E006D0535 /* MarkdownTextViewTests */,
|
||||
7252E0681AF1BD61006D0535 /* Example */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
@@ -244,6 +334,16 @@
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
7252E0671AF1BD61006D0535 /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
7252E0731AF1BD61006D0535 /* Main.storyboard in Resources */,
|
||||
7252E0781AF1BD61006D0535 /* LaunchScreen.xib in Resources */,
|
||||
7252E0751AF1BD61006D0535 /* Images.xcassets in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXResourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
@@ -276,6 +376,15 @@
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
7252E0651AF1BD61006D0535 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
7252E0701AF1BD61006D0535 /* ViewController.swift in Sources */,
|
||||
7252E06E1AF1BD61006D0535 /* AppDelegate.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXTargetDependency section */
|
||||
@@ -284,8 +393,32 @@
|
||||
target = 7252E02C1AF1BC1D006D0535 /* MarkdownTextView */;
|
||||
targetProxy = 7252E03A1AF1BC1E006D0535 /* PBXContainerItemProxy */;
|
||||
};
|
||||
7252E08C1AF1BD82006D0535 /* PBXTargetDependency */ = {
|
||||
isa = PBXTargetDependency;
|
||||
target = 7252E02C1AF1BC1D006D0535 /* MarkdownTextView */;
|
||||
targetProxy = 7252E08B1AF1BD82006D0535 /* PBXContainerItemProxy */;
|
||||
};
|
||||
/* End PBXTargetDependency section */
|
||||
|
||||
/* Begin PBXVariantGroup section */
|
||||
7252E0711AF1BD61006D0535 /* Main.storyboard */ = {
|
||||
isa = PBXVariantGroup;
|
||||
children = (
|
||||
7252E0721AF1BD61006D0535 /* Base */,
|
||||
);
|
||||
name = Main.storyboard;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
7252E0761AF1BD61006D0535 /* LaunchScreen.xib */ = {
|
||||
isa = PBXVariantGroup;
|
||||
children = (
|
||||
7252E0771AF1BD61006D0535 /* Base */,
|
||||
);
|
||||
name = LaunchScreen.xib;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXVariantGroup section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
7252E0411AF1BC1E006D0535 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
@@ -439,6 +572,30 @@
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
7252E0861AF1BD61006D0535 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||
"DEBUG=1",
|
||||
"$(inherited)",
|
||||
);
|
||||
INFOPLIST_FILE = Example/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
7252E0871AF1BD61006D0535 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
INFOPLIST_FILE = Example/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
@@ -469,6 +626,14 @@
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
7252E0851AF1BD61006D0535 /* Build configuration list for PBXNativeTarget "Example" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
7252E0861AF1BD61006D0535 /* Debug */,
|
||||
7252E0871AF1BD61006D0535 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
rootObject = 7252E0241AF1BC1D006D0535 /* Project object */;
|
||||
|
||||
@@ -56,6 +56,8 @@ public struct MarkdownAttributes {
|
||||
default: return nil
|
||||
}
|
||||
}
|
||||
|
||||
public init() {}
|
||||
}
|
||||
|
||||
public var headerAttributes: HeaderAttributes? = HeaderAttributes()
|
||||
@@ -95,4 +97,6 @@ public struct MarkdownAttributes {
|
||||
NSFontAttributeName: UIFont.preferredFontForTextStyle(UIFontTextStyleBody),
|
||||
NSForegroundColorAttributeName: UIColor.darkGrayColor()
|
||||
]
|
||||
|
||||
public init() {}
|
||||
}
|
||||
|
||||
87
README.md
Normal file
87
README.md
Normal file
@@ -0,0 +1,87 @@
|
||||
## MarkdownTextView
|
||||
### Rich Markdown Editing for iOS
|
||||
|
||||
**MarkdownTextView** is an iOS framework for adding rich Markdown editing capabilities. Support for Markdown syntax is implemented inside an easily extensible `NSTextStorage` subclass, with a `UITextView` subclass being provided for convenience.
|
||||
|
||||
### Screenshot
|
||||
|
||||
<img src='screenshot.png' width='374px'>
|
||||
|
||||
### Example App
|
||||
|
||||
Check out the includeded Example app to try out the text view and to see how **MarkdownTextView** is integrated into the project.
|
||||
|
||||
### Getting Started
|
||||
|
||||
The simplest possible usage is as follows:
|
||||
|
||||
```swift
|
||||
let textView = MarkdownTextView(frame: CGRectZero)
|
||||
view.addSubview(textView)
|
||||
```
|
||||
|
||||
This gives you a text view with support for most of the features defined in the original Markdown implementation (strong, emphasis, inline code, code blocks, block quotes, headers) with the default styling provided by the framework.
|
||||
|
||||
|
||||
### Customizing Appearance
|
||||
|
||||
All of the styling can be customized using standard `NSAttributedString` attributes. For example, if you wanted to customize bold text such that it appeared red, you would do this:
|
||||
|
||||
```swift
|
||||
var attributes = MarkdownTextAttributes()
|
||||
attributes.strongAttributes = [
|
||||
NSForegroundColorAttributeName: UIColor.redColor()
|
||||
]
|
||||
let textStorage = MarkdownTextStorage(attributes: attributes)
|
||||
let textView = MarkdownTextView(frame: CGRectZero, textStorage: textStorage)
|
||||
view.addSubview(textView)
|
||||
```
|
||||
|
||||
### Extensions Support
|
||||
|
||||
Extension classes conforming to the `HighlighterType` protocol can be used to add support for unofficial Markdown extensions. The framework comes with the following extensions already implemented:
|
||||
|
||||
From [Github Flavored Markdown](https://help.github.com/articles/github-flavored-markdown/)):
|
||||
|
||||
* `MarkdownStrikethroughHighlighter` - Support for `~~strikethrough~~`
|
||||
* `MarkdownFencedCodeHighlighter` - Support for fenced code blocks
|
||||
* `LinkHighlighter` - Support for auto-linking
|
||||
|
||||
Other:
|
||||
|
||||
* `MarkdownSuperscriptHighlighter` - Support for `super^scripted^text`
|
||||
|
||||
These extensions do not come activated by default. They must manually be added to an instance of `MarkdownTextStorage` as follows:
|
||||
|
||||
```swift
|
||||
let textStorage = MarkdownTextStorage()
|
||||
var error: NSError?
|
||||
if let linkHighlighter = LinkHighlighter(errorPtr: &error) {
|
||||
textStorage.addHighlighter(linkHighlighter)
|
||||
} else {
|
||||
assertionFailure("Error initializing LinkHighlighter: \(error)")
|
||||
}
|
||||
textStorage.addHighlighter(MarkdownStrikethroughHighlighter())
|
||||
textStorage.addHighlighter(MarkdownSuperscriptHighlighter())
|
||||
if let codeBlockAttributes = attributes.codeBlockAttributes {
|
||||
textStorage.addHighlighter(MarkdownFencedCodeHighlighter(attributes: codeBlockAttributes))
|
||||
}
|
||||
|
||||
let textView = MarkdownTextView(frame: CGRectZero, textStorage: textStorage)
|
||||
view.addSubview(textView)
|
||||
```
|
||||
|
||||
### Credits
|
||||
|
||||
* John Gruber's [original Markdown implementation](http://daringfireball.net/projects/markdown/) for most of the regular expressions used in this project.
|
||||
* [RFMarkdownTextView](https://github.com/ruddfawcett/RFMarkdownTextView) for the idea to implement this as an `NSTextStorage` subclass
|
||||
|
||||
### Contact
|
||||
|
||||
* Indragie Karunaratne
|
||||
* [@indragie](http://twitter.com/indragie)
|
||||
* [http://indragie.com](http://indragie.com)
|
||||
|
||||
### License
|
||||
|
||||
MarkdownTextView is licensed under the MIT License. See `LICENSE` for more information.
|
||||
BIN
screenshot.png
Normal file
BIN
screenshot.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 122 KiB |
Reference in New Issue
Block a user