All Projects → andyfinnell → NativeMarkKit

andyfinnell / NativeMarkKit

Licence: other
NativeMark is a flavor of Markdown designed to be rendered by native apps.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to NativeMarkKit

SheeKit
Customize and resize sheets in SwiftUI with SheeKit. Utilise the power of `UISheetPresentationController` and other UIKit features.
Stars: ✭ 56 (+55.56%)
Mutual labels:  uikit, swiftui
LocalConsole
In-app console and debug tools for iOS developers
Stars: ✭ 595 (+1552.78%)
Mutual labels:  uikit, swiftui
Driftwood
Driftwood is a DSL to make Auto Layout easy on iOS, tvOS and macOS.
Stars: ✭ 14 (-61.11%)
Mutual labels:  uikit, appkit
Builder
Demonstrates SwiftUI builder patterns for UIKit and networking.
Stars: ✭ 100 (+177.78%)
Mutual labels:  uikit, swiftui
Invalidating
Backports the new @invalidating property wrapper to older platforms
Stars: ✭ 53 (+47.22%)
Mutual labels:  uikit, appkit
NavigationRouter
A router implementation designed for complex modular apps, written in Swift
Stars: ✭ 89 (+147.22%)
Mutual labels:  uikit, swiftui
iOS14-Resources
A curated collection of iOS 14 projects ranging from SwiftUI to ML, AR etc.
Stars: ✭ 85 (+136.11%)
Mutual labels:  uikit, swiftui
SwiftCurrent
A library for managing complex workflows in Swift
Stars: ✭ 286 (+694.44%)
Mutual labels:  uikit, swiftui
column-text-view-ui
📄 Column Text View is an adaptive UI component that renders text in columns, horizontally [iOS 12, UIKit, TextKit, SwiftUI].
Stars: ✭ 11 (-69.44%)
Mutual labels:  uikit, swiftui
Redux
Manage iOS App state with Redux and Async/Await :)
Stars: ✭ 18 (-50%)
Mutual labels:  uikit, swiftui
DarkModeSwitcher
Simple app for overriding light mode per app on macOS (demo for a blog post)
Stars: ✭ 37 (+2.78%)
Mutual labels:  appkit, swiftui
ikyle.me-code-examples
Smaller code examples from my blog posts on ikyle.me
Stars: ✭ 29 (-19.44%)
Mutual labels:  uikit, appkit
VCore
VCore is a Swift collection containing objects, functions, and extensions that I use for my projects
Stars: ✭ 32 (-11.11%)
Mutual labels:  uikit, swiftui
UIViewPreviewProvider
Allows displaying UIViews inside the Xcode preview canvas
Stars: ✭ 36 (+0%)
Mutual labels:  uikit, swiftui
swiftui-example
SwiftUI 示例,技巧和技术集合,帮助我构建应用程序,解决问题以及了解SwiftUI的实际工作方式。
Stars: ✭ 109 (+202.78%)
Mutual labels:  uikit, swiftui
BottomSheet
Access UISheetPresentationController in SwiftUI on iOS 15 using a simple .bottomSheet modifier.
Stars: ✭ 332 (+822.22%)
Mutual labels:  uikit, swiftui
About Swiftui
Gathering all info published, both by Apple and by others, about new framework SwiftUI.
Stars: ✭ 5,954 (+16438.89%)
Mutual labels:  uikit, swiftui
Render
UIKit a-là SwiftUI.framework [min deployment target iOS10]
Stars: ✭ 2,150 (+5872.22%)
Mutual labels:  uikit, swiftui
SwiftUIKit
📱 UIKit code that is fun to write
Stars: ✭ 71 (+97.22%)
Mutual labels:  uikit, swiftui
ColorUp
An easy way to generate strongly typed Swift extensions for either UIColor or Color based off of your colors within the project's asset catalog.
Stars: ✭ 16 (-55.56%)
Mutual labels:  uikit, swiftui

NativeMarkKit

Tests Swift Package Manager compatible

NativeMark is a flavor of Markdown designed to be rendered by native apps (i.e. it compiles down to native types, not HTML). Specifically, it implements the CommonMark spec with the significant exception of raw HTML tags. NativeMark will treat raw HTML tags as plain text.

The goal of NativeMark is to provide a simple, intuitive way to create styled text in native apps. NativeMarkKit is an implementation of NativeMark for macOS, iOS, and tvOS. NativeMarkKit supports dark mode, dynamic type, and SwiftUI where available.

Requirements

  • Swift 5.1 or greater
  • iOS/tvOS 9 or greater OR macOS 10.11 or greater

Installation

Currently, NativeMarkKit is only available as a Swift Package.

...using a Package.swift file

Open the Package.swift file and edit it:

  1. Add NativeMarkKit repo to the dependencies array.
  2. Add NativeMarkKit as a dependency of the target that will use it
// swift-tools-version:5.1

import PackageDescription

let package = Package(
  // ...snip...
  dependencies: [
    .package(url: "https://github.com/andyfinnell/NativeMarkKit.git", from: "1.0.0")
  ],
  targets: [
    .target(name: "MyTarget", dependencies: ["NativeMarkKit"])
  ]
)

Then build to pull down the dependencies:

$ swift build

...using Xcode

Use the Swift Packages tab on the project to add NativeMarkKit:

  1. Open the Xcode workspace or project that you want to add NativeMarkKit to
  2. In the file browser, select the project to show the list of projects/targets on the right
  3. In the list of projects/targets on the right, select the project
  4. Select the "Swift Packages" tab
  5. Click on the "+" button to add a package
  6. In the "Choose Package Repository" sheet, search for "https://github.com/andyfinnell/NativeMarkKit.git"
  7. Click "Next"
  8. Choose the version rule you want
  9. Click "Next"
  10. Choose the target you want to add NativeMarkKit to
  11. Click "Finish"

Usage

...with views

The easiest way to use NativeMarkKit is to use NativeMarkLabel:

import NativeMarkKit

let label = NativeMarkLabel(nativeMark: "**Hello**, _world_!")

// Assuming myView is an NSView or UIView
myView.addSubview(label)

...with SwiftUI

NativeMarkKit has a basic SwiftUI wrapper around NativeMarkLabel called NativeMarkText:

import SwiftUI
import NativeMarkKit

struct ContentView: View {
    var body: some View {
         NativeMarkText("**Hello**, _world_!")
    }
}

...styling

NativeMarkKit provides a style sheet data structure so NativeMark can be customized to match the styling of the app. By default, NativeMarkLabel and NativeMarkText use the .default StyleSheet to control how NativeMark is rendered. You can modify .default to create a global, default style sheet, or you can .duplicate() .default to create a one off style sheet for a specific use case.

For example, if you wanted links to use a brand color, you could mutate the .default StyleSheet:

StyleSheet.default.mutate(inline: [
    .link: [
        .textColor(.purple)
    ]
])

The above code would cause all NativeMark text using the .default style sheet to render links in purple.

If you only wanted to do this for a specific NativeMarkLabel (or NativeMarkText) you can .duplicate() .default and pass in the new style sheet to the labels that want it.

let purpleLinksStyleSheet = StyleSheet.default.duplicate().mutate(inline: [
    .link: [
        .textColor(.purple)
    ]
])

Then when the NativeMarkLabel is created:

import NativeMarkKit

let label = NativeMarkLabel(nativeMark: "**Hello**, [Apple](https://www.apple.com)!", styleSheet: purpleLinksStyleSheet)

...links

By default NativeMarkKit will open links in the default browser when they are clicked/tapped on. If you want to provide custom behavior instead, you can provide a closure to the NativeMarkLabel.

import NativeMarkKit

let label = NativeMarkLabel(nativeMark: "**Hello**, [Apple](https://www.apple.com)!")
label.onOpenLink = { url in
    // your custom code here
    print("Opening \(url)")
}

Documentation

More documentation.

Acknowledgements

The NativeMarkKit project would like to acknowledge the work of the CommonMark project to document a standardized flavor of Markdown. NativeMarkKit's front end parsing is based on CommonMark's parsing strategy and the reference implementation CommonMark.js. Additionally, this project derives its suite of parsing tests from CommonMark's specs.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].