A Pure Swift implementation of the markdown mark-up language
Swift HTML
Latest commit c2cf93f Mar 21, 2016 @SwiftStudies Fix for Issue #1

Corrected bad template for replacement and created test to catch
Failed to load latest commit information.
Data Tidy up Mar 15, 2016
Sources Fix for Issue #1 Mar 21, 2016
Tests Fix for Issue #1 Mar 21, 2016
.gitignore Improved performance 40x Mar 17, 2016
.travis.yml Update .travis.yml Mar 18, 2016
Package.swift Changes to support Linux Mar 17, 2016
README.md Update README.md Mar 18, 2016


Build Status


A pure Swift markdown implementation consistent with Gruber's 1.0.1 version. It is released under the BSD license so please feel free to use (at your own risk).

Pull requests are very welcome, see the vision for where I would like this to go.


Version 1.0 is a very minor Swift-ification of Gruber's original Perl implementation. Lots of regular expressions. The initial performance of this implementation yielded about 28s to process the large Markdown Syntax test. This has improved in 1.0.2 to 7s with some pretty simple optimization of what's there.

However, I would next like to achieve two things

  1. Refactor to support easier extension for particular variants of Markdown
  2. Change the fundamental strategy from regular expressions to a higher performance scanner. In fact there are some seeds already sown there, but I want to clear out regular expressions. They are slow, opaque and the implementation has significant overhead.

Once again, I would love to receive pull requests towards this goal.

Building and Running with Swift Package Manager

Install Swift toolchain if you don't already have it

If you don't already have the latest Swift tool-chain it, it's not a huge download for the binary (<200Mb), it doesn't impact or need anything specific from XCode (unless you want to integrate them), and it comes with an installer. You can download it here.

Once you've done that all you will need to do is open a terminal window, make sure the latest tool-chain is in your path

export PATH=/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin:"${PATH}"

Change to the SmarkDown package directory (where you can see this readme and the Sources, Tests, and Data directories for example).

Building and running

There are two modules in the package SmarkDown is the library you can use in your own projects, and the second is a command line tool markdown which takes a single parameter (which should be a .md markdown file) and outputs the resultant html. You can do a quick test with

swift build
.build/debug/markdown README.md

You should see the HTML version of the read me! As a side note, you have to love Swift Package Manager... it is so very easy to use and get going with!

Use in your code

There are two ways to use it, it provides an extension to String so you can simply do

let myString = "# Cool\n\nThis markdown'd\n"

or you can explicitly create an instance (which will have some minor performance improvements for repeated calls

let smarkDown = SmarkDown()

Integrating with your project

SmarkDown uses the Swift Package Manager so if you are using this for your builds you simply need to add a dependency to your manifest

import PackageDescription

let package = Package(
    name : "Your Project",
    dependencies : [
        //Add the SmarkDown dependency
        .Package(url:"https://github.com/SwiftStudies/SmarkDown.git", majorVersion:1),

Alternatively you can clone (or download) the repository to your computer and add the following files (if you are cloning then I would suggest adding without copying) to your project

  • SmarkDown.swift
  • SpecialCharacters.swift
  • Strings.swift
  • RegularExpressions.swift

I'd recommend doing this in another target (such as library or framework) as there are some extensions you may not want to be exposed to (i.e. are internal to the module).

Reporting Issues

Please do so using Github's own system.