Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ruddfawcett/Notepad
[iOS] A fully themeable markdown editor with live syntax highlighting.
https://github.com/ruddfawcett/Notepad
cocoapods ios markdown notepad regex syntax-highlighter theme uitextview
Last synced: 4 days ago
JSON representation
[iOS] A fully themeable markdown editor with live syntax highlighting.
- Host: GitHub
- URL: https://github.com/ruddfawcett/Notepad
- Owner: ruddfawcett
- License: mit
- Created: 2016-10-15T04:30:07.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2021-11-14T10:26:25.000Z (about 3 years ago)
- Last Synced: 2024-12-04T07:04:28.504Z (9 days ago)
- Topics: cocoapods, ios, markdown, notepad, regex, syntax-highlighter, theme, uitextview
- Language: Swift
- Homepage: http://rudd.fyi/notepad
- Size: 320 KB
- Stars: 880
- Watchers: 26
- Forks: 106
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-swift - Notepad - A fully themeable markdown editor with live syntax highlighting. (Libs / Text)
- awesome-swift - Notepad - A fully themeable markdown editor with live syntax highlighting. (Libs / Text)
- awesome-ios-star - Notepad - A fully themeable markdown editor with live syntax highlighting. (Text / Other Testing)
- fucking-awesome-swift - Notepad - A fully themeable markdown editor with live syntax highlighting. (Libs / Text)
- awesome-ios - Notepad - A fully themeable markdown editor with live syntax highlighting. (Text / Other Testing)
- awesome-swift - Notepad - [iOS] A fully themeable markdown editor with live syntax highlighting. ` 📝 a year ago ` (Text [🔝](#readme))
README
![](https://cdn.rawgit.com/ruddfawcett/Notepad/master/resources/header.svg)
[![Version](https://img.shields.io/github/release/ruddfawcett/Notepad.svg)](https://github.com/ruddfawcett/Notepad/releases) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) [![CocoaPods compatible](https://img.shields.io/cocoapods/v/Notepad.svg)](https://cocoapods.org/pods/Notepad)
## Usage
```swift
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](Example.xcodeproj) for an [example](Example). For full documentation read [the code](Notepad/Notepad.swift).
### 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:
```swift
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 = truelet 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:
```swift
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](themes.md) 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](Notepad/themes), 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:```json
"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.