Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzalezreal committed Dec 29, 2020
1 parent 28e2be6 commit 43a801b
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Examples/MarkdownUIDemo/Shared/Example.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ extension Example {
id: "style",
title: "Style",
document: #"""
## Document Style
## Markdown Style
By default, MardownUI renders markdown strings using the system fonts and reasonable defaults for paragraph spacing, indent size, heading size, etc.
If you don't want to use the default style, you can provide a custom `MarkdownStyle` by using the `markdownStyle()` modifier:
Expand Down
118 changes: 117 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,119 @@
# MarkdownUI

A description of this package.
MarkdownUI is a library for rendering Markdown in SwiftUI, fully compliant with the [CommonMark Spec](https://spec.commonmark.org/current/).

## Supported Platforms

You can use the `Markdown` SwiftUI view in the following platforms:

* macOS 11.0+
* iOS 14.0+
* tvOS 14.0+

The `NSAttributedString` extension is available in:

* macOS 10.12+
* iOS 11.0+
* tvOS 11.0+
* watchOS 3.0+

## Usage

You can create a `Markdown` view in SwiftUI by providing a CommonMark document.

```swift
Markdown(
#"""
It's very easy to make some words **bold** and other words *italic* with Markdown.
**Want to experiment with Markdown?** Play with the [reference CommonMark
implementation](https://spec.commonmark.org/dingus/).
"""#
)
```

![Markdown text](Screenshots/Text.png)

A Markdown view renders text using a `body` font appropriate for the current platform.
You can choose a different font or customize other properties like the foreground color,
paragraph spacing, or heading styles using the `markdownStyle(_:)` view modifier.

```swift
Markdown(
#"""
## Inline code
If you have inline code blocks, wrap them in backticks: `var example = true`.
"""#
)
.markdownStyle(
MarkdownStyle(
font: .system(.body, design: .serif),
codeFontName: "Menlo",
codeFontSize: .em(0.88)
)
)
```

![Markdown style](Screenshots/Style.png)

A Markdown view always uses all the available width and adjusts its height to fit its
rendered text.

Use the `accentColor(_:)` view modifier to configure the link color.

```swift
Markdown("Play with the [reference CommonMark implementation](https://spec.commonmark.org/dingus/).")
.accentColor(.purple)
```

Use modifiers like `lineLimit(_:)` and `truncationMode(_:)` to configure
how the view handles space constraints.

```swift
Markdown("> Knowledge is power, Francis Bacon.")
.lineLimit(1)
```

You can set the alignment of the text by using the `multilineTextAlignment(_:)` view modifier.

```swift
Markdown(
#"""
There are many different ways to style code with CommonMark. If you
have inline code blocks, wrap them in backticks: `var example = true`.
"""#
)
.multilineTextAlignment(.trailing)
```

![Text alignment](Screenshots/TextAlignment.png)

### Using the NSAttributedString Extension
If you are not yet using SwiftUI, you can use the `NSAttributedString` extension to render Markdown in your app.

```swift
let attributedString = NSAttributedString(
document: #"""
It's very easy to make some words **bold** and other words *italic* with Markdown.
"""#,
style: MarkdownStyle(font: .system(.body))
)
```

## Supported Markdown Elements
MarkdownUI uses the [CommonMark](https://github.com/commonmark/cmark) reference parser and it is fully compliant with the [CommonMark Spec](https://spec.commonmark.org/current/).

You can explore all the capabilities of this package in the [companion demo project](Examples/MarkdownUIDemo).

![Demo](Screenshots/Demo.png)

## Installation
You can add MarkdownUI to an Xcode project by adding it as a package dependency.
1. From the **File** menu, select **Swift Packages › Add Package Dependency…**
1. Enter `https://github.com/gonzalezreal/MarkdownUI` into the package repository URL text field
1. Link **MarkdownUI** to your application target

## Other Libraries
* [CommonMarkAttributedString](https://github.com/mattt/CommonMarkAttributedString)
* [Down](https://github.com/johnxnguyen/Down)
* [AttributedText](https://github.com/gonzalezreal/AttributedText)
Binary file added Screenshots/Demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/Style.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/Text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/TextAlignment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 43a801b

Please sign in to comment.