Notepad - A fully themeable iOS markdown editor with live syntax highlighting.

Overview

Version Carthage compatible CocoaPods compatible

Usage

let notepad = Notepad(frame: view.bounds, themeFile: "one-dark")
view.addSubview(notepad)

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.

Check out the Xcode project for an example. For full documentation read the code.

Extending an Existing Text View with Notepad Features

If you cannot work with the Notepad subclass directly for some reason, you can set up an existing UITextView or NSTextView on your own.

For iOS, you have to initialize all TextKit components yourself. Take the following as a blueprint where you can swap in custom objects:

class ViewController: UIViewController {
    var textView: UITextView!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        let containerSize = CGSize(width: self.view.bounds.width, height: CGFloat.greatestFiniteMagnitude)
        let container = NSTextContainer(size: containerSize)
        container.widthTracksTextView = true

        let layoutManager = NSLayoutManager()
        layoutManager.addTextContainer(container)

        let storage = Storage()
        let theme = Theme("one-dark")
        storage.theme = theme
        storage.addLayoutManager(layoutManager)

        let editor = UITextView(frame: self.view.bounds, textContainer: container)
        editor.backgroundColor = theme.backgroundColor
        editor.tintColor = theme.tintColor
        editor.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    }
}

And for macOS:

class ViewController: NSViewController {
    @IBOutlet var textView: NSTextView!
    let storage = Storage()

    override func viewDidLoad() {
        super.viewDidLoad()

        let theme = Theme("one-dark")
        storage.theme = theme
        textView.backgroundColor = theme.backgroundColor
        textView.insertionPointColor = theme.tintColor
        textView.layoutManager?.replaceTextStorage(storage)
    }
}

Themes

Take a look at all of the themes and swatches when choosing the theme for your Notepad, or as inspiration for a new one.

You can find all of the raw themes in the themes folder, and the file names are case-sensitive.

Custom Regex

Using regex, you can match custom patterns in your Notepad editor by passing a regex attribute in your theme. For example, one that highlights Twitter handles in a teal color:

"handle": {
  "regex": "[@@][a-zA-Z0-9_]{1,20}",
  "color": "#78ddd5"
}

Installation

Copy the source from the Notepad folder to your project, or add Notepad to your Podfile if you're using CocoaPods.

Comments
  • Unable to be used with CocoaPods

    Unable to be used with CocoaPods

    When used via CocoaPods, the Notepad.framework is built and included, but the individual classes aren't able to be used. For example, import Notepad works just fine, but you can't use the Notepad class in code. Perhaps this is because there is no framework header?

    This is in a Swift 3.0 project. I maintain frameworks of my own (e.g. Mapbox-iOS-SDK) so I'm fairly familiar with the process here, though I could be making a dumb mistake.

    The pod try Notepad example just has the Notepad.swift etc. files included directly in its own module, which is why it works.

    bug 
    opened by incanus 14
  • Unable to load your theme file.

    Unable to load your theme file.

    Hello !

    I have added Nodepad to my IOS project but I have this error : [Notepad] Unable to load your theme file. My code :

    import UIKit
    import Foundation
    import Notepad
    
    @IBOutlet weak var textView: UITextView!
    
    override func viewDidLoad() {
            super.viewDidLoad()
                let containerSize = CGSize(width: self.view.bounds.width, height: CGFloat.greatestFiniteMagnitude)
                let container = NSTextContainer(size: containerSize)
                container.widthTracksTextView = true
            
                let layoutManager = NSLayoutManager()
                layoutManager.addTextContainer(container)
            
                let storage = Storage()
                let theme = Theme("one-dark")
                storage.theme = theme
                storage.addLayoutManager(layoutManager)
            
                let editor = UITextView(frame: self.view.bounds, textContainer: container)
                editor.backgroundColor = theme.backgroundColor
                editor.tintColor = theme.tintColor
                editor.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    }
    

    Thank you in advance

    PS : Sorry for my bad English :/

    bug 
    opened by ghost 11
  • Not compatible with Xcode 8.3.2 Or Swift 3.0

    Not compatible with Xcode 8.3.2 Or Swift 3.0

    I was just trying to build the code but it gives me so many errors related to NSAttributedStringKey.

    Error: Use of undeclared type 'NSAttributedStringKey'.

    Is anyone faces this error and resolved this.

    I'm new to Swift 3.0. I will appreciate your help.

    bug enhancement help wanted 
    opened by harjottrantor 11
  • Internal Protection Level

    Internal Protection Level

    initializer is inaccessible due to 'internal' protection level

    I think the Notepad's convenience initializer needs to be made public in order to access it from outside the framework.

    opened by curtisbacon 9
  • Please add the possibility to change the syntax color and clickable links.

    Please add the possibility to change the syntax color and clickable links.

    It's a very good library and I like it because the themes are customizable. But I've tried everything to change the color of the syntax, but I didn't succeed.

    Another problem I found with the links: It's only colored text, but not selectable.

    Best regards.

    enhancement help wanted 
    opened by filippozanfini 4
  • Suggestion box is too big

    Suggestion box is too big

    I have a problem when my TextView starts with a #Title screen shot 2017-11-22 at 9 14 27

    As you can see the cursor and the suggestion box is too big, I guess it uses the title's size value. Is there any way to fix it?

    bug help wanted 
    opened by danielmekis 4
  • fix bold + italic: consider adding traits to a base font instead of requiring font names

    fix bold + italic: consider adding traits to a base font instead of requiring font names

    I found that to get a bold & italic font, coming up with a XYZ-BoldItalic name doesn't work, but adding a font trait via NSFontManager does work.

    Instead of requiring font names in the theme files, my suggestion is to add another property, maybe even call it "traits", where you can specify "bold", "italic", or both.

    • If the current style scope has a font setting, it adds the traits to the font name -- thus making a setting like "font": "Menlo-Bold", traits: [ "bold" ] redundant.
    • If the current style's scope has no font name set, the style will use the base (body) font and add the traits.
    • If no style ever did set a custom font, it falls back to the current system font.

    What do you think?

    enhancement help wanted 
    opened by DivineDominion 4
  • make a Type for built-in themes

    make a Type for built-in themes

    While working with the library, it took me a second to notice that Theme(_:) doesn't load a file from my app target but only from the framework target -- so it's supposed to work with built-in themes only.

    Making this clear with a named parameter, like Theme(builtInThemeName: String), looks awful. But I had an idea:

    // A different name may be desirable
    enum BuiltInTheme: String {
        case oneDark: "themes/one-dark"
        // ...
    }
    

    Then resolving the bundle path can be moved into that type as well.

    The initializer changes to Theme(_ builtIn: BuiltInTheme) and can be called with Theme(.oneDark). Upside: client apps can know which themes are built-in without looking at the source, because the enum cases are easily discoverable in Xcode.

    Also, this frees up the string-based initializer to work with Bundle.main so that client apps can call Theme("custom") to load a resource from the app bundle.

    enhancement help wanted 
    opened by DivineDominion 4
  • Cannot call value of non-function type module<Notepad>

    Cannot call value of non-function type module

    I wanted to give Notepad a try so I added the Pod to my project and I could also import it like so:

    import Notepad
    

    import

    The problem

    As soon as I try to instantiate a Notepad object I get the following error:

    screen shot 2017-01-24 at 15 28 41

    I am using the Xcode 8.2.1

    opened by besi 4
  • macOS pod installation

    macOS pod installation

    When I try to install Notepad via CocoaPod for my macOS app, I get the following error: The platform of the target NameApp (macOS 10.13) is not compatible withNotepad (0.2.4), which does not supportosx.

    Thanks.

    help wanted 
    opened by filippozanfini 3
  • Carthage support

    Carthage support

    By marking the Notepad scheme within the example project public it allows Carthage to build this project as a dependency.

    This is non ideal but it works.

    opened by aaroncrespo 3
  • Hide markdown syntax as cursor leaves the position?

    Hide markdown syntax as cursor leaves the position?

    Is it possible to have the markdown syntax hide as the cursor leaves the text? Sort of like Obsidian does in their live preview mode?

    Eg writing **bold** to only show bold? (Notice that the asterisks have been "hidden")

    opened by erikvlm 4
  • Feature/named capturing groups

    Feature/named capturing groups

    Added two new properties to Style to allow us to iterate through the named capturing groups in the regex, and also to retrieve styles by name.

    This allows us to apply any other style to a named sub-range of the matched range.

    Added an example for h3 to the 'one-dark-custom' style.

    #28

    opened by siburb 2
  • Made the Mac Version Work

    Made the Mac Version Work

    I tried to use this, but the Mac version didn't work. I fixed the errors and got rid of warnings while I was at it. The functionality is no different.

    opened by DrBeta 0
  • Use System Font

    Use System Font

    Hi there,

    Before it all, thanks for sharing this project. It's pretty cool. I was digging around the themes, and will probably create a custom one myself, though I noticed the fonts used are the ones that are listem in the system.

    Is there a way to use the system font, such as UIFont.systemFont(ofSize: CGFloat, weight: UIFont.Weight) ?

    enhancement help wanted 
    opened by ivancantarino 2
Releases(0.3.0)
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
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
Fully open source text editor for iOS written in Swift.

Edhita Fully open source text editor for iOS written in Swift. http://edhita.bornneet.com/ What Edhita means? Edhita (Romaji) == エディタ (Katakana) == Ed

Tatsuya Tobioka 1.2k Jan 1, 2023
iOS & OSX Syntax Highlighter.

Highlightr Highlightr is an iOS & macOS syntax highlighter built with Swift. It uses highlight.js as it core, supports 185 languages and comes with 89

J.P. Illanes 1.4k Dec 23, 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
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
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
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
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
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
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
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
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
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