Skip to content

Commit

Permalink
Initial commit w/ passing test on bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
rob phillips committed May 29, 2016
0 parents commit 69fba2a
Show file tree
Hide file tree
Showing 52 changed files with 47,991 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Pods/
.DS_Store
xcuserdata

# additional ignores that will save us time
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
588 changes: 588 additions & 0 deletions Down.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Down.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?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>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Rob Phillips.

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.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
## Down
[![Coverage Status](https://coveralls.io/repos/github/iwasrobbed/Down/badge.svg?branch=master)](https://coveralls.io/github/iwasrobbed/Down?branch=master)
[![Build Status](https://travis-ci.org/iwasrobbed/Down.svg?branch=master)](https://travis-ci.org/iwasrobbed/Down)
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/iwasrobbed/Down/blob/master/LICENSE)
[![CocoaPods](https://img.shields.io/cocoapods/v/Down.svg?maxAge=2592000)]()
[![Swift](https://img.shields.io/badge/language-Swift-blue.svg)](https://swift.org)

Blazing fast Markdown rendering in Swift, built upon [cmark](https://github.com/jgm/cmark).

Is your app using it? [Let me know!](mailto:rob@desideratalabs.co)

### Installation

Quickly install using [CocoaPods](https://cocoapods.org):

```ruby
pod 'Down'
```

### Robust Performance

>[cmark](https://github.com/jgm/cmark) can render a Markdown version of War and Peace in the blink of an eye (127 milliseconds on a ten year old laptop, vs. 100-400 milliseconds for an eye blink). In our [benchmarks](https://github.com/jgm/cmark/blob/master/benchmarks.md), cmark is 10,000 times faster than the original Markdown.pl, and on par with the very fastest available Markdown processors.
> The library has been extensively fuzz-tested using [american fuzzy lop](http://lcamtuf.coredump.cx/afl). The test suite includes pathological cases that bring many other Markdown parsers to a crawl (for example, thousands-deep nested bracketed text or block quotes).
### Output Formats
* HTML
* XML

### API


### Supports
Swift, ARC & iOS 8+

### Markdown Specification

Down is built upon the [CommonMark](http://commonmark.org) specification.

### A little help from my friends
Please feel free to fork and create a pull request for bug fixes or improvements, being sure to maintain the general coding style, adding tests, and adding comments as necessary.

### Credit
This library is a wrapper around [cmark](https://github.com/jgm/cmark), which is built upon the [CommonMark](http://commonmark.org) Markdown specification.

[cmark](https://github.com/jgm/cmark) is Copyright (c) 2014, John MacFarlane. View [full license](https://github.com/jgm/cmark/blob/master/COPYING).
20 changes: 20 additions & 0 deletions Source/Down.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// Down.swift
// Down
//
// Created by Rob Phillips on 5/28/16.
// Copyright © 2016 Glazed Donut, LLC. All rights reserved.
//

import Foundation

public class Down: DownHTMLRenderable {

public var markdownString: String

@warn_unused_result
public init(markdownString: String) {
self.markdownString = markdownString
}

}
16 changes: 16 additions & 0 deletions Source/Enums & Options/DownErrors.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// DownErrors.swift
// Down
//
// Created by Rob Phillips on 5/28/16.
// Copyright © 2016 Glazed Donut, LLC. All rights reserved.
//

import Foundation

public enum DownErrors: ErrorType {
/**
Indicates that cmark could not properly parse the Markdown for some reason :(
*/
case ParseError
}
59 changes: 59 additions & 0 deletions Source/Enums & Options/DownOptions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// DownOptions.swift
// Down
//
// Created by Rob Phillips on 5/28/16.
// Copyright © 2016 Glazed Donut, LLC. All rights reserved.
//

import Foundation

public struct DownOptions: OptionSetType {
public let rawValue: Int32
public init(rawValue: Int32) { self.rawValue = rawValue }

/**
Default options
*/
public static let Default = DownOptions(rawValue: 0)

// MARK: - Rendering Options

/**
Include a `data-sourcepos` attribute on all block elements
*/
public static let SourcePos = DownOptions(rawValue: 1 << 1)

/**
Render `softbreak` elements as hard line breaks.
*/
public static let HardBreaks = DownOptions(rawValue: 1 << 2)

/**
Suppress raw HTML and unsafe links (`javascript:`, `vbscript:`,
`file:`, and `data:`, except for `image/png`, `image/gif`,
`image/jpeg`, or `image/webp` mime types). Raw HTML is replaced
by a placeholder HTML comment. Unsafe links are replaced by
empty strings.
*/
public static let Safe = DownOptions(rawValue: 1 << 3)

// MARK: - Parsing Options

/**
Normalize tree by consolidating adjacent text nodes.
*/
public static let Normalize = DownOptions(rawValue: 1 << 4)

/**
Validate UTF-8 in the input before parsing, replacing illegal
sequences with the replacement character U+FFFD.
*/
public static let ValidateUTF8 = DownOptions(rawValue: 1 << 5)

/**
Convert straight quotes to curly, --- to em dashes, -- to en dashes.
*/
public static let Smart = DownOptions(rawValue: 1 << 6)

}
35 changes: 35 additions & 0 deletions Source/Renderers/DownHTMLRenderable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// DownHTMLRenderable.swift
// Down
//
// Created by Rob Phillips on 5/28/16.
// Copyright © 2016 Glazed Donut, LLC. All rights reserved.
//

import Foundation
import libcmark

public protocol DownHTMLRenderable: DownRenderable {
@warn_unused_result
func toHTML(options: DownOptions) throws -> String
}

public extension DownHTMLRenderable {

@warn_unused_result
public func toHTML(options: DownOptions = .Default) throws -> String {
var outputString: String?
markdownString.withCString {
let stringLength = Int(strlen($0))
let cBuffer = cmark_markdown_to_html($0, stringLength, options.rawValue)
outputString = String(CString: cBuffer, encoding: NSUTF8StringEncoding)
free(cBuffer)
}

guard let htmlString = outputString else {
throw DownErrors.ParseError
}
return htmlString
}

}
13 changes: 13 additions & 0 deletions Source/Renderers/DownRenderable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// DownRenderable.swift
// Down
//
// Created by Rob Phillips on 5/28/16.
// Copyright © 2016 Glazed Donut, LLC. All rights reserved.
//

import Foundation

public protocol DownRenderable {
var markdownString: String { get set }
}
Loading

0 comments on commit 69fba2a

Please sign in to comment.