From 7abfb6db6191620cc072894bea6ff4c085e280d5 Mon Sep 17 00:00:00 2001 From: Robbie Trencheny Date: Thu, 3 Mar 2016 19:15:31 -0800 Subject: [PATCH] initial attempt at improving plists with html and markdown support --- Classes/Core/HSKBItem.h | 3 ++- Classes/Core/HSKBItem.m | 12 ++++++++++++ Classes/Core/HSKBSource.m | 9 ++++++++- HelpStack.podspec | 1 + 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Classes/Core/HSKBItem.h b/Classes/Core/HSKBItem.h index e0ed48f..d07b1c8 100644 --- a/Classes/Core/HSKBItem.h +++ b/Classes/Core/HSKBItem.h @@ -22,7 +22,7 @@ #import - +#import typedef NS_OPTIONS(NSUInteger, HSKBItemType) { HSKBItemTypeArticle = 0, @@ -56,6 +56,7 @@ typedef NS_OPTIONS(NSUInteger, HSKBItemType) { */ - (id)initAsArticle:(NSString*)title textContent:(NSString*)content kbID:(NSString*)kbID; - (id)initAsArticle:(NSString*)title htmlContent:(NSString*)content baseUrl:(NSString*)baseUrl kbID:(NSString*)kbID; +- (id)initAsArticle:(NSString*)title markdownContent:(NSString*)content baseUrl:(NSString*)baseUrl kbID:(NSString*)kbID; /** Kb will be prepared with given title, content and id, its type will be set as Section. diff --git a/Classes/Core/HSKBItem.m b/Classes/Core/HSKBItem.m index 1a85800..59f5796 100644 --- a/Classes/Core/HSKBItem.m +++ b/Classes/Core/HSKBItem.m @@ -47,6 +47,18 @@ - (id)initAsArticle:(NSString*)title htmlContent:(NSString*)content baseUrl:(NSS return self; } +- (id)initAsArticle:(NSString*)title markdownContent:(NSString*)content baseUrl:(NSString*)baseUrl kbID:(NSString*)kbID +{ + if(self = [super init]) { + self.title = title; + self.htmlContent = [MMMarkdown HTMLStringWithMarkdown:content extensions:MMMarkdownExtensionsGitHubFlavored error:NULL]; + self.baseUrl = baseUrl; + self.itemType = HSKBItemTypeArticle; + self.kb_id = kbID; + } + return self; +} + - (id)initAsSection:(NSString*)title kbID:(NSString*)kbID{ if(self = [super init]) { self.title = title; diff --git a/Classes/Core/HSKBSource.m b/Classes/Core/HSKBSource.m index 4e121c7..0a0ab66 100644 --- a/Classes/Core/HSKBSource.m +++ b/Classes/Core/HSKBSource.m @@ -90,7 +90,14 @@ - (void)readKBArticleFromLocalPList:(void (^)(void))success failure:(void (^)(NS for (NSDictionary *object in articleDict) { - HSKBItem* kb = [[HSKBItem alloc] initAsArticle:[object objectForKey:@"title"] textContent:[object objectForKey:@"content"] kbID:nil]; + HSKBItem* kb = [HSKBItem alloc]; + if ([object objectForKey:@"html"] != nil) { + kb = [[HSKBItem alloc] initAsArticle:[object objectForKey:@"title"] htmlContent:[object objectForKey:@"html"] baseUrl:@"" kbID:nil]; + } else if ([object objectForKey:@"markdown"] != nil) { + kb = [[HSKBItem alloc] initAsArticle:[object objectForKey:@"title"] markdownContent:[object objectForKey:@"markdown"] baseUrl:@"" kbID:nil]; + } else { + kb = [[HSKBItem alloc] initAsArticle:[object objectForKey:@"title"] textContent:[object objectForKey:@"content"] kbID:nil]; + } [articles addObject:kb]; } diff --git a/HelpStack.podspec b/HelpStack.podspec index fb47446..6d77485 100644 --- a/HelpStack.podspec +++ b/HelpStack.podspec @@ -12,6 +12,7 @@ Pod::Spec.new do |s| s.source = { :git => "https://github.com/happyfoxinc/helpstack.git", :tag => "1.1.1", :submodules => true } s.resources = ['Resources/*.png','Resources/*.storyboard'] s.dependency 'AFNetworking', '~> 2.0' + s.dependency 'MMMarkdown', '~> 0.5' s.frameworks = 'UIKit', 'CoreGraphics' s.requires_arc = true