Git Product home page Git Product logo

swiftmark's Introduction

Swift Platforms License Carthage compatible Dash compatible swiftmarklogo

Goals

SwiftMark is not only a wrapper of the C library cmark but it also relies on it to provide users a complete Swift CommonMark framework.
This framework offers high-level API to convert any CommonMark text to HTML, XML and soon LATEX.

Requirements

  • OS X 10.10+ / iOS 8.0+
  • Xcode 7.2+

Setup

Using Carthage

Add github "Pyroh/SwiftMark" ~> 0.9 to your Cartfile and run carthage update. If you need help using Carthage you can take a look at their Getting Started section.

Manually

  1. Clone this repository.
  2. Build the SwiftMark project.
  3. Add the resulting framework file to your project.
  4. ?
  5. Profit.

Synchronous vs. Asynchronous

With SwiftMark you are able to convert CommonMark text synchronously or asynchronously.

Synchronous method:

Simply use a conversion functions:

let md = "**Swift***Mark*"
if let html = try? commonMarkToHTML(md){
	// html = "<p><b>Swift</b><em>Mark</em></p>"
	// do something with html…
}

Asynchronous method

Asynchronous convert process rely on Grand Central Dispatch through NSOperation subclasses.
You should instantiate one of this subclasses and manage result or failure in a closure:

let md = "**Swift***Mark*"

let op = SwiftMarkToHTMLOperation(text: md)
op.conversionCompleteBlock = { html in
	// html = "<p><b>Swift</b><em>Mark</em></p>"
	// do something with html…
}
op.failureBlock = { error in
	// Handle the error.
}

// Provided that queue is an NSOperationQueue object.
queue.addOperation(op)

// If you don't want to use NSOperationQueue just
queue.start()

Documentation

Full documentation is available here

Functions

SwiftMark offers two global functions:

  • commonMarkToHTML(str: String, options: SwiftMarkOptions = .Default)
  • commonMarkToXML(str: String, options: SwiftMarkOptions = .Default)

These two functions produce HTML or XML code based on a given CommonMark text. Each function can throw an error if there's been a problem during the parsing process. (For available options please refer to full documentation)

Operations

You can dispatch the conversion process on another thread if you prefer. SwiftMark enables you to do so simply by using a subclass of SwiftMarkOperation which is a subclass of NSOperation. There's two of these subclasses available:

  • SwiftMarkToHTMLOperation
  • SwiftMarkToXMLOperation

I think each class is self-explanatory.

In order to convert a CommonMark text you must :

  1. Create a new SwiftMarkOperation object
    let op = SwiftMarkToHTMLOperation(text: md)

  2. Set the closure which will be executed once the conversion is done
    op.conversionCompleteBlock = { html in …}

  3. Optionally set the closure which will be called in case of failure
    op.failureBlock = { error in …}

Now it's up to you:

  • You add your operation to an NSOperationQueue.
  • You manually start your operation.

Generate documentation

  • Be sure jazzy is installed.
  • Go to Documentation folder.
  • Run sh gendoc.sh or chmod +x gendoc.sh && ./gendoc.sh

TODO

  • LATEX support.
  • iOS sample code.
  • Give user access to document's AST… the Swift way…
  • Tests.
  • CocoaPods support.

License

SwiftMark is released under the MIT license. See LICENSE for details.

The cmark library used to build SwiftMark is Copyright (c) 2014, John MacFarlane. More information in COPYING.

swiftmark's People

Contributors

l65l avatar pyroh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.