Swift markdown library
Swift
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 11 commits behind crossroadlabs:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Markdown.xcodeproj
Markdown
Tests
.gitignore
.travis.yml
Cartfile
LICENSE
LICENSE.LESSER
Package.swift
README.md

README.md

Markdown

Markdown

🐧 linux: ready Build Status Carthage compatible Platform OS X | Linux ![Swift version](https://img.shields.io/badge/Swift-2.1 | 2.2-blue.svg) ![GitHub license](https://img.shields.io/badge/license-LGPL v3-green.svg) GitHub release

Full markdown support for Swift - wrapper over Discount (this actually is what GitHub uses deep down)

Goals

Markdown library was mainly introduced to fulfill the needs of Swift Express - web application server side framework for Swift.

Still we hope it will be useful for everybody else.

Happy marking down ;)

Getting started

Installation

Prerequisites

First of all you need to install Discount.

OS X:
#this one install a static library, so don't worry about redistribution
brew install discount
Linux:
sudo apt-get install libmarkdown2-dev

Package Manager

Add the following dependency to your Package.swift:

.Package(url: "https://github.com/crossroadlabs/Markdown.git", majorVersion: 0)

Run swift build and build your app. Package manager is supported on OS X, but it's still recommended to be used on Linux only.

Carthage

Add the following to your Cartfile:

github "crossroadlabs/Markdown"

Run carthage update and follow the steps as described in Carthage's README.

Examples

Hello Markdown

let md = try Markdown(string:"# Hello Markdown")
let document = try md.document()
print(document)

The output will be the following:

<h1>Hello Markdown</h1>

Metadata

let md = try Markdown(string:"% test\n% daniel\n% 02.03.2016\n")
            
let title = md.title!
let author = md.author!
let date = md.date

print("Title: ", title)
print("Author: ", author)
print("Date: ", date)

The output will be the following:

Title: test
Author: daniel
Date: 02.03.2016

Table of contents

let md = try Markdown(string:"# test header", options: .TableOfContents)
let toc = try md.tableOfContents()
print(toc)

The output will be the following:

<ul>
 <li><a href=\"#test.header\">test header</a></li>
</ul>

Style

let md = try Markdown(string:"<style>background-color: yellow;</style>\n# test header")
let css = try md.css()
print(css)

The output will be the following:

<style>background-color: yellow;</style>

Have a nice marking down ;)

Contributing

To get started, sign the Contributor License Agreement.

Crossroad Labs by Crossroad Labs