Swift markdown library

Related tags

Text Markdown
Overview

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

Comments
  • Build error (Swift 3.0 Xcode 8.0 Beta 2)

    Build error (Swift 3.0 Xcode 8.0 Beta 2)

    Added to Package.swift, then on swift build:

    Cloning https://github.com/crossroadlabs/CDiscount.git
    HEAD is now at 207cbc3 added modulemap
    Resolved version: 0.1.0
    Compile Swift Module 'Markdown' (3 sources)
    <module-includes>:1:9: note: in file included from <module-includes>:1:
    #import "cdiscount.h"
            ^
    /.../Packages/CDiscount-0.1.0/cdiscount.h:22:10: error: 'mkdio.h' file not found
    #include <mkdio.h>
             ^
    
    enhancement question wontfix 
    opened by iamjono 13
  • The package Discount has no Package.swift error

    The package Discount has no Package.swift error

    Hi, I tried the installation using the swift package manager, but it throws an error saying:

    Empty manifest file is not supported anymore. Use `swift package init` to autogenerate.
    error: The package at `....../Packages/CDiscount.git' has no Package.swift for the specific version: 0.1.0
    

    What can I do to actually install this library?

    Thanks

    opened by nestormata 0
  • Memory leak

    Memory leak

    There's a memory leak in Markdown.swift at line 47:

    var dest = [UnsafeMutablePointer<Int8>?](repeating: UnsafeMutablePointer<Int8>.allocate(capacity: 1), count: 1)
    

    This line is allocating space for a pointer to be returned, but in doing so is also allocating an actual pointer to one byte of memory. When fun is called to process data and return a result, the allocated pointer is overwritten and the one-byte allocation (16 actual bytes) is lost.

    Since all you need is space for a pointer here, and since the array is an array-of-optionals, you can just replace that line with this:

    var dest: [UnsafeMutablePointer<Int8>?] = [nil]
    

    No allocation, so no leak.

    opened by SiriusBrent 0
  • 'libmarkdown' error `'mkdio.h' file not found` when using the Markdown library after installing Discount via brew

    'libmarkdown' error `'mkdio.h' file not found` when using the Markdown library after installing Discount via brew

    Hello!

    After running brew install discount I can see that discount did properly install. However, Swift can't compile my app without using the following command:

    swift build -Xcc -I/usr/local/include -Xlinker -L/usr/local/lib -Xswiftc -target -Xswiftc x86_64-apple-macosx10.12
    

    I'm really new to this type of development and unfamiliar with the environment, so I am hoping this is not a real issue and is just some dummy error on my part.

    This seems to be related to #3, which should have been resolved via a release for libmarkdown. Is there a status update on that?

    Do you mind providing some insight on the issue?

    PS. I'm following the Server-Side Swift book by @twostraws and it's been excellent. I've reached a project in the book that uses your library and that's when I found this issue.

    System info

    macOS 10.12.5 Xcode8.3.3

    swift build output

    ➜  Project11 swift build
    note: you may be able to install libmarkdown using your system-packager:
    
        brew install discount
    
    note: you may be able to install libmarkdown using your system-packager:
    
        brew install discount
    
    note: you may be able to install libmarkdown using your system-packager:
    
        brew install discount
    
    Compile Swift Module 'libc' (1 sources)
    Compile Swift Module 'Polymorphic' (2 sources)
    Compile Swift Module 'Jay' (21 sources)
    Compile Swift Module 'PathIndexable' (2 sources)
    Compile Swift Module 'SwiftSlug' (1 sources)
    Compile Swift Module 'Markdown' (3 sources)
    Compile Swift Module 'Spectre' (8 sources)
    Compile Swift Module 'Cryptor' (10 sources)
    Compile Swift Module 'KituraTemplateEngine' (1 sources)
    Compile Swift Module 'SwiftyJSON' (2 sources)
    Compile Swift Module 'Socket' (3 sources)
    Compile Swift Module 'LoggerAPI' (1 sources)
    Compile Swift Module 'Core' (29 sources)
    Compile Swift Module 'HeliumLogger' (2 sources)
    Compile Swift Module 'Node' (22 sources)
    <module-includes>:1:9: note: in file included from <module-includes>:1:
    #import "cdiscount.h"
            ^
    /Users/zk/Developer/Server/Project11/.build/checkouts/CDiscount.git-4318135343521947030/cdiscount.h:22:10: error: 'mkdio.h' file not found
    #include <mkdio.h>
             ^
    /Users/zk/Developer/Server/Project11/.build/checkouts/Markdown.git--5008474681835546292/Sources/Markdown/Markdown.swift:22:8: error: could not build Objective-C module 'CDiscount'
    import CDiscount
           ^
    <module-includes>:1:9: note: in file included from <module-includes>:1:
    #import "cdiscount.h"
            ^
    /Users/zk/Developer/Server/Project11/.build/checkouts/CDiscount.git-4318135343521947030/cdiscount.h:22:10: error: 'mkdio.h' file not found
    #include <mkdio.h>
             ^
    /Users/zk/Developer/Server/Project11/.build/checkouts/Markdown.git--5008474681835546292/Sources/Markdown/Markdown.swift:22:8: error: could not build Objective-C module 'CDiscount'
    import CDiscount
           ^
    <module-includes>:1:9: note: in file included from <module-includes>:1:
    #import "cdiscount.h"
            ^
    /Users/zk/Developer/Server/Project11/.build/checkouts/CDiscount.git-4318135343521947030/cdiscount.h:22:10: error: 'mkdio.h' file not found
    #include <mkdio.h>
             ^
    /Users/zk/Developer/Server/Project11/.build/checkouts/Markdown.git--5008474681835546292/Sources/Markdown/Markdown.swift:22:8: error: could not build Objective-C module 'CDiscount'
    import CDiscount
           ^
    <unknown>:0: error: build had 1 command failures
    error: exit(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /Users/zk/Developer/Server/Project11/.build/debug.yaml
    

    With -Xlinker and -target, but not -Xcc

    ➜  Project11 swift build -Xlinker -L/usr/local/lib -Xswiftc -target -Xswiftc x86_64-apple-macosx10.12
    note: you may be able to install libmarkdown using your system-packager:
    
        brew install discount
    
    note: you may be able to install libmarkdown using your system-packager:
    
        brew install discount
    
    note: you may be able to install libmarkdown using your system-packager:
    
        brew install discount
    
    Compile Swift Module 'Markdown' (3 sources)
    Compile Swift Module 'Jay' (21 sources)
    Compile Swift Module 'libc' (1 sources)
    Compile Swift Module 'Polymorphic' (2 sources)
    Compile Swift Module 'PathIndexable' (2 sources)
    Compile Swift Module 'SwiftSlug' (1 sources)
    Compile Swift Module 'Spectre' (8 sources)
    Compile Swift Module 'KituraTemplateEngine' (1 sources)
    Compile Swift Module 'Cryptor' (10 sources)
    Compile Swift Module 'SwiftyJSON' (2 sources)
    Compile Swift Module 'Socket' (3 sources)
    Compile Swift Module 'LoggerAPI' (1 sources)
    Compile Swift Module 'Core' (29 sources)
    Compile Swift Module 'HeliumLogger' (2 sources)
    Compile Swift Module 'Node' (22 sources)
    <module-includes>:1:9: note: in file included from <module-includes>:1:
    #import "cdiscount.h"
            ^
    /Users/zk/Developer/Server/Project11/.build/checkouts/CDiscount.git-4318135343521947030/cdiscount.h:22:10: error: 'mkdio.h' file not found
    #include <mkdio.h>
             ^
    /Users/zk/Developer/Server/Project11/.build/checkouts/Markdown.git--5008474681835546292/Sources/Markdown/Markdown.swift:22:8: error: could not build Objective-C module 'CDiscount'
    import CDiscount
           ^
    <module-includes>:1:9: note: in file included from <module-includes>:1:
    #import "cdiscount.h"
            ^
    /Users/zk/Developer/Server/Project11/.build/checkouts/CDiscount.git-4318135343521947030/cdiscount.h:22:10: error: 'mkdio.h' file not found
    #include <mkdio.h>
             ^
    /Users/zk/Developer/Server/Project11/.build/checkouts/Markdown.git--5008474681835546292/Sources/Markdown/Markdown.swift:22:8: error: could not build Objective-C module 'CDiscount'
    import CDiscount
           ^
    <module-includes>:1:9: note: in file included from <module-includes>:1:
    #import "cdiscount.h"
            ^
    /Users/zk/Developer/Server/Project11/.build/checkouts/CDiscount.git-4318135343521947030/cdiscount.h:22:10: error: 'mkdio.h' file not found
    #include <mkdio.h>
             ^
    /Users/zk/Developer/Server/Project11/.build/checkouts/Markdown.git--5008474681835546292/Sources/Markdown/Markdown.swift:22:8: error: could not build Objective-C module 'CDiscount'
    import CDiscount
           ^
    <unknown>:0: error: build had 1 command failures
    error: exit(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /Users/zk/Developer/Server/Project11/.build/debug.yaml
    

    The "working" command

    ➜  Project11 swift build -Xcc -I/usr/local/include -Xlinker -L/usr/local/lib -Xswiftc -target -Xswiftc x86_64-apple-macosx10.12
    note: you may be able to install libmarkdown using your system-packager:
    
        brew install discount
    
    note: you may be able to install libmarkdown using your system-packager:
    
        brew install discount
    
    note: you may be able to install libmarkdown using your system-packager:
    
        brew install discount
    
    Compile Swift Module 'Markdown' (3 sources)
    Compile Swift Module 'libc' (1 sources)
    Compile Swift Module 'Polymorphic' (2 sources)
    Compile Swift Module 'Jay' (21 sources)
    Compile Swift Module 'PathIndexable' (2 sources)
    Compile Swift Module 'SwiftSlug' (1 sources)
    Compile Swift Module 'Spectre' (8 sources)
    Compile Swift Module 'Cryptor' (10 sources)
    Compile Swift Module 'KituraTemplateEngine' (1 sources)
    Compile Swift Module 'SwiftyJSON' (2 sources)
    Compile Swift Module 'Socket' (3 sources)
    Compile Swift Module 'LoggerAPI' (1 sources)
    Compile Swift Module 'Core' (29 sources)
    Compile Swift Module 'HeliumLogger' (2 sources)
    Compile Swift Module 'Node' (22 sources)
    Compile Swift Module 'PathKit' (1 sources)
    Compile Swift Module 'Stencil' (19 sources)
    Compile Swift Module 'KituraStencil' (1 sources)
    Compile Swift Module 'JSON' (9 sources)
    Compile Swift Module 'MySQL' (11 sources)
    Compile Swift Module 'SSLService' (1 sources)
    Compile CHTTPParser http_parser.c
    Compile CHTTPParser utils.c
    Linking CHTTPParser
    Compile Swift Module 'KituraNet' (34 sources)
    Compile Swift Module 'Kitura' (43 sources)
    Compile Swift Module 'project11' (1 sources)
    Linking ./.build/debug/project11
    
    opened by dotZak 2
  • "Module file was created by an older version" Error

    Hi,

    I'm installing the library using Carthage, but after following all the steps and doing the import, Xcode says:

    Module file was created by an older version of the compiler; rebuild 'Markdown' and try again: /Volumes/MacOSHibrido/Users/nestor/Documents/freelances/ios-10-course/TestAppLayout/Carthage/Build/Mac/Markdown.framework/Modules/Markdown.swiftmodule/x86_64.swiftmodule
    

    I tried running: carthage update --no-use-binaries

    But then I got the following error:

    *** Fetching Markdown
    *** Fetching CDiscount
    *** Checking out CDiscount at "0.1.0"
    *** Checking out Markdown at "0.1.0"
    *** xcodebuild output can be found in /var/folders/5p/16f9d01140n53_65ftsbjh4h0000gn/T/carthage-xcodebuild.R8yKD7.log
    *** Building scheme "Markdown" in Markdown.xcodeproj
    ** CLEAN FAILED **
    
    
    The following build commands failed:
        Check dependencies
    (1 failure)
    ** BUILD FAILED **
    
    
    The following build commands failed:
        Check dependencies
    (1 failure)
    warning: no umbrella header found for target 'Markdown', module map will not be generated
    warning: no umbrella header found for target 'Markdown', module map will not be generated
    A shell task (/usr/bin/xcrun xcodebuild -project /Volumes/MacOSHibrido/Users/nestor/Documents/freelances/ios-10-course/TestAppLayout/Carthage/Checkouts/Markdown/Markdown.xcodeproj -scheme Markdown -configuration Release ONLY_ACTIVE_ARCH=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES clean build) failed with exit code 65:
    ** CLEAN FAILED **
    
    
    The following build commands failed:
        Check dependencies
    (1 failure)
    ** BUILD FAILED **
    
    
    The following build commands failed:
        Check dependencies
    (1 failure)
    

    How do I fix this?

    opened by nestormata 2
  • text is cut before the end

    text is cut before the end

    I use the library to display a "terms and conditions" text. The generated document is cut before the end of the source text.

    the debug process:

    let contents = try NSString(contentsOfFile: filepath, usedEncoding: nil) as Stringgives:

    [...]se réserve la faculté de modifier à tout moment, de plein droit et sans formalités, les présentes CGU[...]

    let md = try Markdown(string:contents)
    let document = try md.document()
    
    

    gives :

    se réserve la faculté de modifier à tout moment, de plein droi

    "

    opened by neywen 3
Releases(1.0.0-alpha.2)
Owner
Crossroad Labs
Crossroad Labs s.r.o.
Crossroad Labs
Marky Mark is a parser written in Swift that converts markdown into native views.

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

M2mobi 287 Nov 29, 2022
A Pure Swift implementation of the markdown mark-up language

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

Swift Studies 67 Jan 24, 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
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

Frank Rausch 41 Dec 19, 2022
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

Matt Diephouse 1.2k Dec 14, 2022
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

Matteo Gavagnin 539 Dec 29, 2022
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

Indragie Karunaratne 676 Dec 7, 2022
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

Simon Fairbairn 1.5k Dec 22, 2022
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

Indragie Karunaratne 1.2k Dec 12, 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 262 Nov 23, 2021
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: "

Michael Henry 4 Apr 19, 2022
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

Peter Salz 6 Jan 15, 2022
Simple, keyboard-first, markdown note-taking for MacOS

QuickDown Simple, keyboard-first, markdown note-taking for MacOS Main Features Global Hotkey: ⌘-⌥-N Save Note: ⌘-S Launch on Login (Optional) Addition

Alexis Rondeau 50 Nov 29, 2022