Swiftpack.co - Package - ntrupin/swiftmark

swiftmark

swiftmark is a simple, lightweight way to convert Markdown to HTML in Swift. With no dependencies (other than Foundation) and an intuitive library, swiftmark fits in to any project without a hassle.

Contents

Requirements

  • iOS 8.0+ / Mac OS X 10.9+ / tvOS 9.0+ / watchOS 2.0+
  • Xcode 8.0+

Installation

swiftmark can be installed through the Swift Package Manager.

Swift Package Manager

Swift Package Manager requires Swift version 4.0 or higher. Then,

  1. Create a Package.swift file. It should look like:
dependencies: [
    .package(url: "https://github.com/ntrupin/swiftmark.git", from: "1.0.0")
]
  1. Run swift build to fetch and compile swiftmark so you may use it.

In Xcode 11+, there is a Swift Packages tab in the project window. You can add swiftmark authomatically through there by clicking the "+" button and adding "https://github.com/ntrupin/swiftmark.git" as a required Swift package.

Usage

Gettings started with swiftmark is as simple as adding import swiftmark to the top of the file you wish to use it in.

Once the library has been imported, you may call the conversion function from within your code. The class accepts a string, which is your Markdown, and returns a string, which is the HTML created from your Markdown.

import swiftmark

// MARK: Classic
let md = swiftmark("# Hello, world!")
let html = md.html()
print(html) // prints <h1>Hello, world!</h1>

Examples

Below are some examples of using swiftmark.

Initialization

let md = swiftmark("# Hello, world!")

You may also initialize swiftmark with multi-line strings.

let md = swiftmark("""
# Hello, world!

This is a multi-line string.
""")

Convert to HTML

When given:

# Hello, world!

We are using [swiftmark](https://github.com/ntrupin/swiftmark/)!

swiftmark will return:

<h1>Hello, world!</h1>

We are using <a href="https://github.com/ntrupin/swiftmark/">swiftmark</a>!

Github

link
Stars: 0
Help us keep the lights on

Dependencies

Used By

Total: 1