Skip to content

Commit

Permalink
Release 0.1.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverLetterer committed Mar 18, 2014
1 parent afa1f2a commit 0b380cf
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 27 deletions.
16 changes: 16 additions & 0 deletions GHMarkdownParser.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Pod::Spec.new do |s|
s.name = 'GHMarkdownParser'
s.version = '0.1.0'
s.license = 'MIT'
s.summary = 'A GitHub Flavored Markdown parser for iOS and Mac OS, based on discount.'
s.homepage = 'https://github.com/OliverLetterer/GHMarkdownParser'
s.author = { 'Oliver Letterer' => 'oliver.letterer@gmail.com' }
s.source = { :git => 'https://github.com/OliverLetterer/GHMarkdownParser.git', :tag => s.version.to_s, :submodules => 'true' }
s.source_files = 'discount/config.h', 'discount/setup.c', 'discount/tags.{h,c}',
'discount/html5.c', 'discount/emmatch.c', 'discount/Csio.c', 'discount/xml.c', 'discount/resource.c',
'discount/generate.c', 'discount/markdown.{h,c}', 'discount/mkdir.{c,h}', 'discount/cstring.h',
'discount/amalloc.{h,c}', 'discount/mkdio.{h,c}', 'GHMarkdownParser/**/*.{h,m}'
s.xcconfig = { 'OTHER_LDFLAGS' => '-ObjC -all_load', 'HEADER_SEARCH_PATHS' => '"${PODS_ROOT}/GHMarkdownParser/discount"' }
s.resources = 'discount/blocktags'
s.requires_arc = true
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?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>IDESourceControlProjectFavoriteDictionaryKey</key>
<false/>
<key>IDESourceControlProjectIdentifier</key>
<string>AC14F571-B174-4CFD-86A8-53F8647B99B6</string>
<key>IDESourceControlProjectName</key>
<string>GHMarkdownParser</string>
<key>IDESourceControlProjectOriginsDictionary</key>
<dict>
<key>193DF35C-ABEF-4A63-8DE8-FEEEE3E58386</key>
<string>ssh://github.com/OliverLetterer/discount.git</string>
<key>DCBE6C60-F59F-46B8-B293-E3435415C037</key>
<string>ssh://github.com/OliverLetterer/GHMarkdownParser.git</string>
</dict>
<key>IDESourceControlProjectPath</key>
<string>GHMarkdownParser/GHMarkdownParser.xcodeproj/project.xcworkspace</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>193DF35C-ABEF-4A63-8DE8-FEEEE3E58386</key>
<string>../../../discount</string>
<key>DCBE6C60-F59F-46B8-B293-E3435415C037</key>
<string>../../..</string>
</dict>
<key>IDESourceControlProjectURL</key>
<string>ssh://github.com/OliverLetterer/GHMarkdownParser.git</string>
<key>IDESourceControlProjectVersion</key>
<integer>110</integer>
<key>IDESourceControlProjectWCCIdentifier</key>
<string>DCBE6C60-F59F-46B8-B293-E3435415C037</string>
<key>IDESourceControlProjectWCConfigurations</key>
<array>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>193DF35C-ABEF-4A63-8DE8-FEEEE3E58386</string>
<key>IDESourceControlWCCName</key>
<string>discount</string>
</dict>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>DCBE6C60-F59F-46B8-B293-E3435415C037</string>
<key>IDESourceControlWCCName</key>
<string>GHMarkdownParser</string>
</dict>
</array>
</dict>
</plist>
7 changes: 4 additions & 3 deletions GHMarkdownParser/GHMarkdownParser/GHMarkdownParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ typedef enum {
} GHMarkdownOptions;



/** Parses human-readable input in the Markdown format and converts it to HTML. */
@interface GHMarkdownParser : NSObject

/** Option flags for Markdown parsing. By default these are all off. */
@property GHMarkdownOptions options;
@property (nonatomic, assign) GHMarkdownOptions options;

/** If set, Github-Flavored Markdown extensions are supported. */
@property BOOL githubFlavored;
@property (nonatomic, assign) BOOL githubFlavored;

/** If set, relative URLs will be prefixed with this absolute URL. */
@property NSURL* baseURL;
@property (nonatomic, strong) NSURL *baseURL;


/** Converts a Markdown string to HTML using this parser instance's settings. */
Expand Down
48 changes: 24 additions & 24 deletions GHMarkdownParser/GHMarkdownParser/GHMarkdownParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,67 +9,67 @@
#import "GHMarkdownParser.h"
#import "markdown.h"

#if !__has_feature(objc_arc)
#error This project requires arc
#endif

// Declared in mkdio.h, but we can't include that after including markdown.
extern void mkd_with_html5_tags(void);


@implementation GHMarkdownParser

@synthesize options=_options, githubFlavored=_githubFlavored, baseURL=_baseURL;
@implementation GHMarkdownParser

+ (void) initialize {
+ (void)initialize {
// Enable recognition of HTML5 tags
mkd_with_html5_tags();
}

+ (NSString *)HTMLStringFromMarkdownString:(NSString *)markdownString {
GHMarkdownParser* parser = [[self alloc] init];
NSString* html = [parser HTMLStringFromMarkdownString:markdownString];
#if !__has_feature(objc_arc)
[parser release];
#endif
GHMarkdownParser *parser = [[self alloc] init];
NSString *html = [parser HTMLStringFromMarkdownString:markdownString];
return html;
}


+ (NSString *)flavoredHTMLStringFromMarkdownString:(NSString *)markdownString {
GHMarkdownParser* parser = [[self alloc] init];
GHMarkdownParser *parser = [[self alloc] init];
parser.githubFlavored = YES;
NSString* html = [parser HTMLStringFromMarkdownString:markdownString];
#if !__has_feature(objc_arc)
[parser release];
#endif
NSString *html = [parser HTMLStringFromMarkdownString:markdownString];
return html;
}


- (NSString *)HTMLStringFromMarkdownString:(NSString *)markdownString {
NSData* mdData = [markdownString dataUsingEncoding:NSUTF8StringEncoding];
NSData *mdData = [markdownString dataUsingEncoding:NSUTF8StringEncoding];
Document *document;
if (_githubFlavored)
document = gfm_string(mdData.bytes, mdData.length, _options);
else
document = mkd_string(mdData.bytes, mdData.length, _options);
if (!document)

if (_githubFlavored) {
document = gfm_string(mdData.bytes, (int)mdData.length, _options);
} else {
document = mkd_string(mdData.bytes, (int)mdData.length, _options);
}

if (!document) {
return nil;
}

if (_baseURL)
if (_baseURL) {
mkd_basename(document, (char*)_baseURL.absoluteString.UTF8String);
}

NSString* html = nil;
NSString *html = nil;
if (mkd_compile(document, _options)) {
char *HTMLUTF8 = NULL;
int length = mkd_document(document, &HTMLUTF8);
if (length >= 0) {
html = [[NSString alloc] initWithBytes:HTMLUTF8
length:length
encoding:NSUTF8StringEncoding];
#if !__has_feature(objc_arc)
[html autorelease];
#endif
}
mkd_cleanup(document);
}

return html;
}

Expand Down

0 comments on commit 0b380cf

Please sign in to comment.