Refactor styling (#23)
- Refactor blockQuote styling
Problem
The BlockQuote text container styling is very specific to BlockQuote. It can’t be used by other text containers (list, codeblock, future tables, etc).
Solution
Remove the BlockQuote styling, and instead add Margin, Border, Padding, and a background color. Currently only BlockQuote text container will use them, but future commits should allow other text containers to use them.
- Make code blocks a text container layout
Re-implement the custom code block style with generic block styling.
Also, fixed a bug where the attributes on the container break were wrong. They had the new container’s styling applied, but TextKit considers them part of the old container.
Lists now use standard block attributes
List items now respect text container styling
Consolidate inline background drawing
Remove BackgroundBorder as it’s not longer used. Replace InlineBackgroundValue with InlineContainerStyleValue, which uses TextContainerStyle, just like blocks. Also make sure 1pt borders are crisp.
NativeMarkKit
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. It also supports some of Github Flavored Markdown’s extensions, such as strikethrough.
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
Installation
Currently, NativeMarkKit is only available as a Swift Package.
…using a Package.swift file
Open the Package.swift file and edit it:
dependencies
array.Then build to pull down the dependencies:
…using Xcode
Use the Swift Packages tab on the project to add NativeMarkKit:
Usage
…with views
The easiest way to use NativeMarkKit is to use
NativeMarkLabel
:…with SwiftUI
NativeMarkKit has a basic SwiftUI wrapper around
NativeMarkLabel
calledNativeMarkText
:…styling
NativeMarkKit provides a style sheet data structure so NativeMark can be customized to match the styling of the app. By default,
NativeMarkLabel
andNativeMarkText
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
: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
(orNativeMarkText
) you can.duplicate()
.default
and pass in the new style sheet to the labels that want it.Then when the
NativeMarkLabel
is created:…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
.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.
For Github Flavored Markdown extensions the Github Flavored Markdown Spec was used.