Rich Markdown editing control for iOS

Overview

MarkdownTextView

Rich Markdown Editing for iOS

MarkdownTextView is an iOS framework for adding rich Markdown editing capabilities. Support for Markdown syntax is implemented inside an easily extensible NSTextStorage subclass, with a UITextView subclass being provided for convenience.

Screenshot

Example App

Check out the includeded Example app to try out the text view and to see how MarkdownTextView is integrated into the project.

Installation

With CocoaPods:
pod "MarkdownTextView"
With Carthage:
github "indragiek/MarkdownTextView"

Getting Started

The simplest possible usage is as follows:

let textView = MarkdownTextView(frame: CGRectZero)
view.addSubview(textView)

This gives you a text view with support for most of the features defined in the original Markdown implementation (strong, emphasis, inline code, code blocks, block quotes, headers) with the default styling provided by the framework.

Customizing Appearance

All of the styling can be customized using standard NSAttributedString attributes. For example, if you wanted to customize bold text such that it appeared red, you would do this:

var attributes = MarkdownTextAttributes()
attributes.strongAttributes = [
	NSForegroundColorAttributeName: UIColor.redColor()
]
let textStorage = MarkdownTextStorage(attributes: attributes)
let textView = MarkdownTextView(frame: CGRectZero, textStorage: textStorage)
view.addSubview(textView)

Extensions Support

Extension classes conforming to the HighlighterType protocol can be used to add support for unofficial Markdown extensions. The framework comes with the following extensions already implemented:

From Github Flavored Markdown:

  • MarkdownStrikethroughHighlighter - Support for ~~strikethrough~~
  • MarkdownFencedCodeHighlighter - Support for fenced code blocks
  • LinkHighlighter - Support for auto-linking

Other:

  • MarkdownSuperscriptHighlighter - Support for super^scripted^text

These extensions do not come activated by default. They must manually be added to an instance of MarkdownTextStorage as follows:

let textStorage = MarkdownTextStorage()
var error: NSError?
if let linkHighlighter = LinkHighlighter(errorPtr: &error) {
    textStorage.addHighlighter(linkHighlighter)
} else {
    assertionFailure("Error initializing LinkHighlighter: \(error)")
}
textStorage.addHighlighter(MarkdownStrikethroughHighlighter())
textStorage.addHighlighter(MarkdownSuperscriptHighlighter())
if let codeBlockAttributes = attributes.codeBlockAttributes {
    textStorage.addHighlighter(MarkdownFencedCodeHighlighter(attributes: codeBlockAttributes))
}

let textView = MarkdownTextView(frame: CGRectZero, textStorage: textStorage)
view.addSubview(textView)

Credits

Contact

License

MarkdownTextView is licensed under the MIT License. See LICENSE for more information.

You might also like...
A simple and customizable Markdown Parser for Swift
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

      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.

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

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.

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.

Markdown in SwiftUI, and some other interesting components.
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

Swift markdown library
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.

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

`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

Leverages Apple's Swift-based Markdown parser to output NSAttributedString.
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

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

Comments
  • Memory Leak

    Memory Leak

    Causes ~50 memory leaks in its current state.

    My code for reference:

    lazy var composeTextView: MarkdownTextView = {

      // MarkdownTextView
        var attributes = MarkdownAttributes()
        attributes.defaultAttributes = [
            NSFontAttributeName: UIFont.systemFont(ofSize: constants.compose.textFontSize),
            NSForegroundColorAttributeName: constants.compose.textFontColor
        ]
        
        let textStorage = MarkdownTextStorage(attributes: attributes)
        do {
            textStorage.addHighlighter(try LinkHighlighter())
        } catch let error {
            fatalError("Error initializing LinkHighlighter: \(error)")
        }
        textStorage.addHighlighter(MarkdownStrikethroughHighlighter())
        textStorage.addHighlighter(MarkdownSuperscriptHighlighter())
        if let codeBlockAttributes = attributes.codeBlockAttributes {
            textStorage.addHighlighter(MarkdownFencedCodeHighlighter(attributes: codeBlockAttributes))
        }
        
        let textView = MarkdownTextView(frame: CGRect.zero, textStorage: textStorage)
        //textView.font = UIFont.systemFont(ofSize: constants.compose.textFontSize)
        //textView.textColor = constants.compose.textFontColor
        textView.backgroundColor = .clear
        //textView.textColor = constants.compose.textFontColor
        textView.font = UIFont.systemFont(ofSize: constants.compose.textFontSize)
        //textView.tintColor = constants.compose.textFontColor
        textView.textContainerInset = UIEdgeInsets(top: 5, left: 9, bottom: constants.compose.helpButton.padding, right: 9)
        
        textView.isEditable = true
        textView.isSelectable = true
        textView.isScrollEnabled = true
        textView.showsVerticalScrollIndicator = false
        textView.showsHorizontalScrollIndicator = false
        
        textView.keyboardAppearance = UIKeyboardAppearance.light
        
        // testing purposes
        textView.layer.borderWidth = constants.testingBorderWidth
        textView.layer.borderColor = UIColor.red.cgColor
        
        return textView
    }()
    
    opened by saoudrizwan 1
  • Carthage is not supported

    Carthage is not supported

    Framework scheme is set to shared after tag 1.0.0. While using Carthage, it fetch the newest tag (1.0.0) and at that time the scheme is not shared which cause a error. Add a new tag can fix that.

    opened by kukushi 1
  • How do I add Markdown to a UITextView which has been added in the storyboard ?

    How do I add Markdown to a UITextView which has been added in the storyboard ?

     @IBOutlet weak var texView:  MarkdownTextView!
      var textStorage: MarkdownTextStorage?
    
      let attributes = MarkdownAttributes()
            let textStorage = MarkdownTextStorage(attributes: attributes)
            do {
                textStorage.addHighlighter(try LinkHighlighter())
            } catch let error {
                fatalError("Error initializing LinkHighlighter: \(error)")
            }
            textStorage.addHighlighter(MarkdownStrikethroughHighlighter())
            textStorage.addHighlighter(MarkdownSuperscriptHighlighter())
            if let codeBlockAttributes = attributes.codeBlockAttributes {
                textStorage.addHighlighter(MarkdownFencedCodeHighlighter(attributes: codeBlockAttributes))
            }
    
    
    
    ..... 
    
    opened by JDSX 0
  • Pasting Markdown Text then crash

    Pasting Markdown Text then crash

    I created some md texts in this view. When I copy some md text then paste at the first line of the text area, it crashes with the following message:

    2017-10-06 08:06:36.430585+0200 xxx[59886:2281740] /Users/clear/Dropbox/dev/Traces/libs/MarkdownTextView-master/MarkdownTextView/MarkdownTextStorage.swift: 14: 12: fatal error: use of unimplemented initializer 'init()' for class 'MarkdownTextView.MarkdownTextStorage'

    opened by strongwillow 0
Releases(1.0.1)
Owner
Indragie Karunaratne
Indragie Karunaratne
A standalone, flexible API that provides a full-featured rich text editor for iOS applications.

Twitter Text Editor A standalone, flexible API that provides a full featured rich text editor for iOS applications. This provides a robust text attrib

Twitter 2.8k Dec 29, 2022
A rich-text editor for iOS

DTRichTextEditor This project aims to provide a replacement for Apple's severely limited UITextView and to allow for editing attributed strings. It co

Cocoanetics 346 Oct 8, 2022
Powerful text framework for iOS to display and edit rich text.

YYText Powerful text framework for iOS to display and edit rich text. (It's a component of YYKit) Features UILabel and UITextView API compatible High

null 8.8k Jan 4, 2023
A beautiful rich text WYSIWYG editor for iOS with a syntax highlighted source view

ZSSRichTextEditor The Editor ZSSRichTextEditor is a beautiful Rich Text WYSIWYG Editor for iOS. It includes all of the standard editor tools one would

Nic Hubbard 3.7k Dec 31, 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 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
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
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
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