Browse Source

Fixes some formatting issues and adds more example text

Simon Fairbairn 5 years ago
parent
commit
b095feaca5

+ 1 - 1
Gemfile.lock

@@ -72,7 +72,7 @@ GEM
     faraday_middleware (0.13.1)
       faraday (>= 0.7.4, < 1.0)
     fastimage (2.1.7)
-    fastlane (2.140.0)
+    fastlane (2.141.0)
       CFPropertyList (>= 2.3, < 4.0.0)
       addressable (>= 2.3, < 3.0.0)
       babosa (>= 1.0.2, < 2.0.0)

+ 14 - 16
SwiftyMarkdown/SwiftyMarkdown.swift

@@ -209,13 +209,7 @@ If that is not set, then the system default will be used.
 	public init(string : String ) {
 		self.string = string
 		super.init()
-		#if os(macOS)
-		self.setFontColorForAllStyles(with: .labelColor)
-		#elseif !os(watchOS)
-		if #available(iOS 13.0, tvOS 13.0, *) {
-			self.setFontColorForAllStyles(with: .label)
-		}
-		#endif
+		self.setup()
 	}
 	
 	/**
@@ -235,6 +229,10 @@ If that is not set, then the system default will be used.
 			return nil
 		}
 		super.init()
+		self.setup()
+	}
+	
+	func setup() {
 		#if os(macOS)
 		self.setFontColorForAllStyles(with: .labelColor)
 		#elseif !os(watchOS)
@@ -377,14 +375,14 @@ extension SwiftyMarkdown {
 		case .unorderedList:
 			lineProperties = body
 			
-			  let paragraphStyle = NSMutableParagraphStyle()
-			  let nonOptions = [NSTextTab.OptionKey: Any]()
-			  paragraphStyle.tabStops = [
-				  NSTextTab(textAlignment: .left, location: 20, options: nonOptions)]
-			  paragraphStyle.defaultTabInterval = 20
-			  paragraphStyle.headIndent = 20
-			 
-			 attributes[.paragraphStyle] = paragraphStyle
+			let paragraphStyle = NSMutableParagraphStyle()
+			let nonOptions = [NSTextTab.OptionKey: Any]()
+			paragraphStyle.tabStops = [
+			  NSTextTab(textAlignment: .left, location: 20, options: nonOptions)]
+			paragraphStyle.defaultTabInterval = 20
+			paragraphStyle.headIndent = 20
+
+			attributes[.paragraphStyle] = paragraphStyle
 			finalTokens.insert(Token(type: .string, inputString: "\(self.bullet)\t"), at: 0)
 		default:
 			lineProperties = body
@@ -442,7 +440,7 @@ extension SwiftyMarkdown {
 			#endif
 			
 			if styles.contains(.code) {
-				attributes[.foregroundColor] = self.code.color
+				attributes[.foregroundColor] = self.color(for: self.code)
 				attributes[.font] = self.font(for: line, characterOverride: .code)
 			} else {
 				// Switch back to previous font

+ 4 - 3
SwiftyMarkdownExample/SwiftyMarkdownExample/Base.lproj/Main.storyboard

@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15702" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15705" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
     <device id="retina4_7" orientation="portrait" appearance="dark"/>
     <dependencies>
         <deployment identifier="iOS"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15704"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15706"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <scenes>
@@ -21,6 +21,7 @@
                         <subviews>
                             <textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" editable="NO" usesAttributedText="YES" translatesAutoresizingMaskIntoConstraints="NO" id="qZP-CU-74n">
                                 <rect key="frame" x="16" y="0.0" width="343" height="583"/>
+                                <color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
                                 <attributedString key="attributedText"/>
                                 <textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
                                 <dataDetectorType key="dataDetectorTypes" link="YES"/>
@@ -55,7 +56,7 @@
                                 </subviews>
                             </stackView>
                         </subviews>
-                        <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+                        <color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
                         <constraints>
                             <constraint firstItem="qZP-CU-74n" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leadingMargin" id="1yU-8N-26a"/>
                             <constraint firstAttribute="trailingMargin" secondItem="qZP-CU-74n" secondAttribute="trailing" id="F5p-iG-zTB"/>

+ 3 - 1
SwiftyMarkdownExample/SwiftyMarkdownExample/ViewController.swift

@@ -37,11 +37,13 @@ class ViewController: UIViewController {
 		
 		if let url = Bundle.main.url(forResource: "example", withExtension: "md"), let md = SwiftyMarkdown(url: url) {
 			md.h2.fontName = "AvenirNextCondensed-Bold"
-			md.h2.color = UIColor.red
+			md.h2.color = UIColor.blue
 			md.h2.alignment = .center
 			
 			md.code.fontName = "CourierNewPSMT"
 			
+			md.body.color = .red
+			
 			md.blockquotes.fontStyle = .italic
 		
 			md.underlineLinks = true

+ 1 - 0
SwiftyMarkdownExample/SwiftyMarkdownExample/example.md

@@ -26,6 +26,7 @@ It ignores random * and correctly handles escaped \*asterisks\* and \_underlines
 - And
 - Unordered
 - Lists
+	- Maybe an indented item?
 - Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.