Browse Source

Add MarkdownKit

marinofaggiana 5 years ago
parent
commit
b3accb71b7

+ 1 - 0
Cartfile

@@ -18,6 +18,7 @@ github "AssistoLab/DropDown" "v2.3.13"
 github "krzyzanowskim/OpenSSL" "1.0.218"
 github "huri000/SwiftEntryKit" "1.2.3"
 github "scenee/FloatingPanel"
+github "ivanbruel/MarkdownKit"
 
 github "https://github.com/marinofaggiana/FastScroll" "master"
 github "https://github.com/marinofaggiana/AFNetworking" "master"

+ 2 - 1
Cartfile.resolved

@@ -11,6 +11,7 @@ github "danielsaidi/Sheeeeeeeeet" "3.0.9"
 github "dzenbot/DZNEmptyDataSet" "v1.8.1"
 github "huri000/QuickLayout" "3.0.0"
 github "huri000/SwiftEntryKit" "1.2.3"
+github "ivanbruel/MarkdownKit" "1.6"
 github "jdg/MBProgressHUD" "1.1.0"
 github "kishikawakatsumi/UICKeyChainStore" "v2.1.2"
 github "krzyzanowskim/OpenSSL" "1.0.218"
@@ -20,7 +21,7 @@ github "marinofaggiana/FastScroll" "81967c2309d29bc2c330d422da612160a30bade8"
 github "nextcloud/ios-communication-library" "v0.51"
 github "realm/realm-cocoa" "v4.1.1"
 github "rechsteiner/Parchment" "v1.7.0"
-github "scenee/FloatingPanel" "v1.7.1"
+github "scenee/FloatingPanel" "v1.7.2"
 github "tilltue/TLPhotoPicker" "2.0.7"
 github "weichsel/ZIPFoundation" "0.9.10"
 github "yahoojapan/SwiftyXMLParser" "5.1.0"

+ 5 - 0
Nextcloud.xcodeproj/project.pbxproj

@@ -559,6 +559,7 @@
 		F7DBC37F23325E2E001A85BA /* NCXMLGetAppPasswordParser.m in Sources */ = {isa = PBXBuildFile; fileRef = F7DBC37E23325E2E001A85BA /* NCXMLGetAppPasswordParser.m */; };
 		F7DBC38023325E2E001A85BA /* NCXMLGetAppPasswordParser.m in Sources */ = {isa = PBXBuildFile; fileRef = F7DBC37E23325E2E001A85BA /* NCXMLGetAppPasswordParser.m */; };
 		F7DBC38123325E2E001A85BA /* NCXMLGetAppPasswordParser.m in Sources */ = {isa = PBXBuildFile; fileRef = F7DBC37E23325E2E001A85BA /* NCXMLGetAppPasswordParser.m */; };
+		F7DBD82C23E46A4700ECB7C6 /* MarkdownKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F7DBD82B23E46A4700ECB7C6 /* MarkdownKit.framework */; };
 		F7DFAA8A22E22EF100FC4527 /* NCShareLinkMenuView.xib in Resources */ = {isa = PBXBuildFile; fileRef = F7DFAA8922E22EF100FC4527 /* NCShareLinkMenuView.xib */; };
 		F7DFB7E0219C312D00680748 /* NCRichDocumentTemplate.m in Sources */ = {isa = PBXBuildFile; fileRef = F7DFB7DF219C312D00680748 /* NCRichDocumentTemplate.m */; };
 		F7DFB7E1219C312D00680748 /* NCRichDocumentTemplate.m in Sources */ = {isa = PBXBuildFile; fileRef = F7DFB7DF219C312D00680748 /* NCRichDocumentTemplate.m */; };
@@ -1371,6 +1372,7 @@
 		F7DBC37B23325E01001A85BA /* NCAppConfigView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCAppConfigView.swift; sourceTree = "<group>"; };
 		F7DBC37D23325E2D001A85BA /* NCXMLGetAppPasswordParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NCXMLGetAppPasswordParser.h; sourceTree = "<group>"; };
 		F7DBC37E23325E2E001A85BA /* NCXMLGetAppPasswordParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NCXMLGetAppPasswordParser.m; sourceTree = "<group>"; };
+		F7DBD82B23E46A4700ECB7C6 /* MarkdownKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MarkdownKit.framework; path = Carthage/Build/iOS/MarkdownKit.framework; sourceTree = "<group>"; };
 		F7DE9AB01F482FA5008DFE10 /* sv */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sv; path = sv.lproj/Localizable.strings; sourceTree = "<group>"; };
 		F7DFAA8922E22EF100FC4527 /* NCShareLinkMenuView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NCShareLinkMenuView.xib; sourceTree = "<group>"; };
 		F7DFB7DE219C312D00680748 /* NCRichDocumentTemplate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NCRichDocumentTemplate.h; sourceTree = "<group>"; };
@@ -1523,6 +1525,7 @@
 				F75153242226920200323DDC /* FastScroll.framework in Frameworks */,
 				F7C40C122199BA620004137E /* RealmSwift.framework in Frameworks */,
 				F78AA20621F783E900D0F205 /* SwiftRichString.framework in Frameworks */,
+				F7DBD82C23E46A4700ECB7C6 /* MarkdownKit.framework in Frameworks */,
 				F74AFCE922E8B025003DE61F /* FSCalendar.framework in Frameworks */,
 				F7D4B6982295666E000C2C86 /* FirebaseMLVision.framework in Frameworks */,
 				F7D4B6862295663D000C2C86 /* FirebaseCore.framework in Frameworks */,
@@ -2898,6 +2901,7 @@
 		F7FC7D541DC1F93700BB2C6A /* Frameworks */ = {
 			isa = PBXGroup;
 			children = (
+				F7DBD82B23E46A4700ECB7C6 /* MarkdownKit.framework */,
 				371B5A3223D0BD5500FAFAE9 /* FloatingPanel.framework */,
 				F765608A23BF80A400765969 /* SwiftEntryKit.framework */,
 				F765608623BF806C00765969 /* QuickLayout.framework */,
@@ -3395,6 +3399,7 @@
 				"$(SRCROOT)/Carthage/Build/iOS/QuickLayout.framework",
 				"$(SRCROOT)/Carthage/Build/iOS/SwiftEntryKit.framework",
 				"$(SRCROOT)/Carthage/Build/iOS/FloatingPanel.framework",
+				"$(SRCROOT)/Carthage/Build/iOS/MarkdownKit.framework",
 			);
 			outputPaths = (
 			);

+ 9 - 3
iOSClient/RichWorkspace/NCRichWorkspace.swift

@@ -23,23 +23,29 @@
 
 
 import Foundation
-import SwiftRichString
+import MarkdownKit
 
 @objc class NCViewRichWorkspace: UIView {
     
     @objc @IBOutlet weak var textView: UITextView!
     @objc @IBOutlet weak var textViewTopConstraint: NSLayoutConstraint!
 
+    let markdownParser = MarkdownParser(font: UIFont.systemFont(ofSize: 15))
+    var richWorkspaceText: String = ""
     let gradientLayer: CAGradientLayer = CAGradientLayer()
 
     required init?(coder: NSCoder) {
         super.init(coder: coder)
+        
+        markdownParser.header.font = UIFont.systemFont(ofSize: 25)
     }
 
     @objc func load(richWorkspaceText: String) {
-        let richWorkspaceCommon = NCRichWorkspaceCommon()
         
-        richWorkspaceCommon.setRichWorkspaceText(richWorkspaceText, textView: textView)
+        if richWorkspaceText != self.richWorkspaceText {
+            textView.attributedText = markdownParser.parse(richWorkspaceText)
+            self.richWorkspaceText = richWorkspaceText
+        }
         setGradient()
     }
     

+ 0 - 55
iOSClient/RichWorkspace/NCRichWorkspaceCommon.swift

@@ -23,7 +23,6 @@
 
 import Foundation
 import NCCommunication
-import SwiftRichString
 
 @objc class NCRichWorkspaceCommon: NSObject {
 
@@ -108,58 +107,4 @@ import SwiftRichString
             }
         }
     }
-    
-    @objc func setRichWorkspaceText(_ richWorkspaceText: String, textView: UITextView) {
-           
-           let h1 = Style {
-               $0.font = UIFont.systemFont(ofSize: 25, weight: .bold)
-               $0.color = NCBrandColor.sharedInstance.textView
-           }
-           let h2 = Style {
-               $0.font = UIFont.systemFont(ofSize: 23, weight: .bold)
-               $0.color = NCBrandColor.sharedInstance.textView
-           }
-           let h3 = Style {
-               $0.font = UIFont.systemFont(ofSize: 21, weight: .bold)
-               $0.color = NCBrandColor.sharedInstance.textView
-           }
-           let h4 = Style {
-               $0.font = UIFont.systemFont(ofSize: 19, weight: .bold)
-               $0.color = NCBrandColor.sharedInstance.textView
-           }
-           let h5 = Style {
-               $0.font = UIFont.systemFont(ofSize: 17, weight: .bold)
-               $0.color = NCBrandColor.sharedInstance.textView
-           }
-           let h6 = Style {
-               $0.font = UIFont.systemFont(ofSize: 15, weight: .bold)
-               $0.color = NCBrandColor.sharedInstance.textView
-           }
-           let normal = Style {
-               $0.font = UIFont.systemFont(ofSize: 15)
-               $0.color = NCBrandColor.sharedInstance.textView
-           }
-          
-           var richWorkspaceStyling = ""
-           let richWorkspaceArray = richWorkspaceText.components(separatedBy: "\n")
-           for string in richWorkspaceArray {
-               if string.hasPrefix("# ") {
-                   richWorkspaceStyling = richWorkspaceStyling + "<h1>" + string.replacingOccurrences(of: "# ", with: "") + "</h1>\r\n"
-               } else if string.hasPrefix("## ") {
-                   richWorkspaceStyling = richWorkspaceStyling + "<h2>" + string.replacingOccurrences(of: "## ", with: "") + "</h2>\r\n"
-               } else if string.hasPrefix("### ") {
-                   richWorkspaceStyling = richWorkspaceStyling + "<h3>" + string.replacingOccurrences(of: "### ", with: "") + "</h3>\r\n"
-               } else if string.hasPrefix("#### ") {
-                   richWorkspaceStyling = richWorkspaceStyling + "<h4>" + string.replacingOccurrences(of: "#### ", with: "") + "</h4>\r\n"
-               } else if string.hasPrefix("##### ") {
-                   richWorkspaceStyling = richWorkspaceStyling + "<h5>" + string.replacingOccurrences(of: "##### ", with: "") + "</h5>\r\n"
-               } else if string.hasPrefix("###### ") {
-                   richWorkspaceStyling = richWorkspaceStyling + "<h6>" + string.replacingOccurrences(of: "###### ", with: "") + "</h6>\r\n"
-               } else {
-                   richWorkspaceStyling = richWorkspaceStyling + string + "\r\n"
-               }
-           }
-           
-           textView.attributedText = richWorkspaceStyling.set(style: StyleGroup(base: normal, ["h1": h1, "h2": h2, "h3": h3, "h4": h4, "h5": h5, "h6": h6]))
-       }
 }

+ 6 - 3
iOSClient/RichWorkspace/NCViewerRichWorkspace.swift

@@ -23,6 +23,7 @@
 
 import Foundation
 import NCCommunication
+import MarkdownKit
 
 @objc class NCViewerRichWorkspace: UIViewController, UIAdaptivePresentationControllerDelegate {
 
@@ -30,6 +31,7 @@ import NCCommunication
     
     private let appDelegate = UIApplication.shared.delegate as! AppDelegate
     private let richWorkspaceCommon = NCRichWorkspaceCommon()
+    private let markdownParser = MarkdownParser(font: UIFont.systemFont(ofSize: 15))
     @objc public var richWorkspaceText: String = ""
     @objc public var serverUrl: String = ""
    
@@ -37,6 +39,7 @@ import NCCommunication
         super.viewDidLoad()
         
         presentationController?.delegate = self
+        markdownParser.header.font = UIFont.systemFont(ofSize: 25)
         
         let closeItem = UIBarButtonItem(title: NSLocalizedString("_back_", comment: ""), style: .plain, target: self, action: #selector(closeItemTapped(_:)))
         self.navigationItem.leftBarButtonItem = closeItem
@@ -44,7 +47,7 @@ import NCCommunication
         let editItem = UIBarButtonItem(image: UIImage(named: "actionSheetModify"), style: UIBarButtonItem.Style.plain, target: self, action: #selector(editItemAction(_:)))
         self.navigationItem.rightBarButtonItem = editItem
 
-        richWorkspaceCommon.setRichWorkspaceText(richWorkspaceText, textView: textView)
+        textView.attributedText = markdownParser.parse(richWorkspaceText)
         
         NotificationCenter.default.addObserver(self, selector: #selector(self.changeTheming), name: NSNotification.Name(rawValue: "changeTheming"), object: nil)
         changeTheming()
@@ -62,7 +65,7 @@ import NCCommunication
                 NCManageDatabase.sharedInstance.setDirectory(ocId: metadataFolder.ocId, serverUrl: metadataFolder.serverUrl, richWorkspace: metadataFolder.richWorkspace, account: account)
                 self.richWorkspaceText = metadataFolder.richWorkspace
                 self.appDelegate.activeMain.richWorkspaceText = self.richWorkspaceText
-                self.richWorkspaceCommon.setRichWorkspaceText(self.richWorkspaceText, textView: self.textView)
+                self.textView.attributedText = self.markdownParser.parse(self.richWorkspaceText)
             }
         }
     }
@@ -73,7 +76,7 @@ import NCCommunication
     
     @objc func changeTheming() {
         appDelegate.changeTheming(self, tableView: nil, collectionView: nil, form: false)
-        richWorkspaceCommon.setRichWorkspaceText(richWorkspaceText, textView: textView)
+        textView.attributedText = markdownParser.parse(richWorkspaceText)
     }
     
     @objc func closeItemTapped(_ sender: UIBarButtonItem) {