A Pure Swift implementation of the markdown mark-up language

Related tags

Text SmarkDown
Overview

Build Status

SmarkDown

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.

Vision

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"
print(myString.markdown)

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

let smarkDown = SmarkDown()
print(smarkDown.markdown(myString))

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.

You might also like...
AttributedString Markdown initializer with custom styling
AttributedString Markdown initializer with custom styling

AttributedString Markdown initializer with custom styling AttributedString in iOS 15 and macOS 12 comes with a Markdown initializer. But: There is no

An Objective-C framework for converting Markdown to HTML.

MMMarkdown MMMarkdown is an Objective-C framework for converting Markdown to HTML. It is compatible with OS X 10.7+, iOS 8.0+, tvOS, and watchOS. Unli

Markdown syntax highlighter for iOS
Markdown syntax highlighter for iOS

Marklight Markdown syntax highlighter for iOS and macOS. Description Marklight is a drop in component to easily add realtime Markdown syntax highlight

Rich Markdown editing control for iOS
Rich Markdown editing control for iOS

MarkdownTextView Rich Markdown Editing for iOS MarkdownTextView is an iOS framework for adding rich Markdown editing capabilities. Support for Markdow

Converts Markdown files and strings into NSAttributedStrings with lots of customisation options.
Converts Markdown files and strings into NSAttributedStrings with lots of customisation options.

SwiftyMarkdown 1.0 SwiftyMarkdown converts Markdown files and strings into NSAttributedStrings using sensible defaults and a Swift-style syntax. It us

Markdown parsing and rendering for iOS and OS X
Markdown parsing and rendering for iOS and OS X

CocoaMarkdown Markdown parsing and rendering for iOS and macOS CocoaMarkdown is a cross-platform framework for parsing and rendering Markdown, built o

Markdown parser for iOS

Marky Mark Marky Mark is a parser written in Swift that converts markdown into native views. The way it looks it highly customizable and the supported

A Github action for creating generic run report using Markdown
A Github action for creating generic run report using Markdown

create-report A Github action for creating generic run report (using Markdown!) - uses: michaelhenry/[email protected] with: report-title: "

Generate help centers for your iOS apps, with Markdown
Generate help centers for your iOS apps, with Markdown

Generate help centers for your iOS apps, with Markdown! All you need to do is wr

Comments
  • Auto-insert <br />

    Auto-insert

    If a
    is auto-inserted (as a result of a double space followed by a newline) after auto-linked text then an additional angle brace can appear, for example

    <mailto:[email protected]>  \n
    Next line
    

    Can result in

    <a href="mailto:[email protected]">[email protected]</a>
    >Next line
    
    bug 
    opened by SwiftStudies 1
  • CommonMark compliance

    CommonMark compliance

    From the readme I can’t see any information about whether it comply to CommonMark. However, this project is listed as CommonMark parser in their Wiki. Please clarify the situation. If it is never intended, I would update that Wiki.

    opened by FranklinYu 1
  • Error with Xcode8

    Error with Xcode8

    $ swift build
    warning: refname '1.0.8' is ambiguous.
    warning: refname '1.0.8' is ambiguous.
    HEAD is now at c2cf93f Fix for Issue #1
    Resolved version: 1.0.8
    myProject/Packages/SmarkDown.git/Package.swift:8:5: error: argument 'targets' must precede argument 'dependencies'
        targets : [
        ^
    Can't parse Package.swift manifest file because it contains invalid format. Fix Package.swift file format and try again.
    error: The package at `myProject/Packages/SmarkDown.git' has no Package.swift for the specific version: 1.0.8
    

    after adding .Package(url: "https://github.com/SwiftStudies/SmarkDown.git", majorVersion: 1) to my Package.swift

    opened by niklassaers 1
  • Installation section organization

    Installation section organization

    Hey, your library is really interesting.

    The only problem I found was the README.md, which needs an organization in the Installation Section I created this iOS Open source Readme Template so you can take a look on how to make it better. If you want, I can help you to organize the lib.

    What are your thoughts? 😄

    opened by lfarah 0
Releases(1.0.8)
  • 1.0.8(Mar 21, 2016)

  • 1.0.7(Mar 18, 2016)

    I've added support for Linux (for both this package and its dependencies). Tests are still not building but the library and executable are fully working (Linux XCTests just require more boiler plate at the moment, so there's some work to do).

    Source code(tar.gz)
    Source code(zip)
Owner
Swift Studies
Swift Studies
Render Markdown text in SwiftUI, preview based on the Marked implementation

Markdown Render Markdown text in SwiftUI. It is a preview based on the Marked implementation. swiftui-markdown.mov Installation You can add MarkdownUI

小弟调调™ 26 Dec 20, 2022
A simple and customizable Markdown Parser for Swift

MarkdownKit MarkdownKit is a customizable and extensible Markdown parser for iOS and macOS. It supports many of the standard Markdown elements through

Bruno Oliveira 687 Dec 18, 2022
Swift markdown library

Markdown ![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.

Crossroad Labs 79 Oct 9, 2022
`resultBuilder` support for `swift-markdown`

SwiftMarkdownBuilder resultBuilder support for swift-markdown. The default way to build Markdown in swift-markdown is to use varargs initializers, e.g

DocZ 9 May 31, 2022
Leverages Apple's Swift-based Markdown parser to output NSAttributedString.

Markdownosaur ?? Markdownosaur uses Apple's excellent and relatively new Swift Markdown library to analyze a Markdown source, and then takes that anal

Christian Selig 232 Dec 20, 2022
Blazing fast Markdown / CommonMark rendering in Swift, built upon cmark.

Down Blazing fast Markdown (CommonMark) rendering in Swift, built upon cmark v0.29.0. Is your app using it? Let us know! If you're looking for iwasrob

John Nguyen 2k Dec 19, 2022
MarkdownView is a WKWebView based UI element, and internally use bootstrap, highlight.js, markdown-it.

MarkdownView is a WKWebView based UI element, and internally use bootstrap, highlight.js, markdown-it.

Keita Oouchi 1.8k Dec 21, 2022
Notepad - A fully themeable iOS markdown editor with live syntax highlighting.

Notepad is just like any other UITextView, but you need to use the convenience initializer in order to use the themes. To create a new theme, copy one of the existing themes and edit the JSON.

Rudd Fawcett 802 Dec 31, 2022
Markdown in SwiftUI, and some other interesting components.

RoomTime RoomTime is a bundle of tools developed in my app RoomTime Lite. ( ?? RoomTime Lite is still in development) Features TextArea AutoWrap Markd

Chen SiWei 56 Dec 20, 2022
Markdown parser for iOS

Marky Mark Marky Mark is a parser written in Swift that converts markdown into native views. The way it looks it highly customizable and the supported

M2mobi 254 Jun 11, 2021