在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):gonzalezreal/MarkdownUI开源软件地址(OpenSource Url):https://github.com/gonzalezreal/MarkdownUI开源编程语言(OpenSource Language):Swift 99.2%开源软件介绍(OpenSource Introduction):MarkdownUIMarkdownUI is a Swift package for rendering Markdown in SwiftUI, fully compliant with the CommonMark Spec. Supported PlatformsYou can use MarkdownUI in the following platforms:
UsageYou can create a Markdown("You can try **CommonMark** [here](https://spec.commonmark.org/dingus/).") If you have already parsed a Markdown-formatted string into a CommonMark document, you can
initialize a let document = try! Document(
markdown: "You can try **CommonMark** [here](https://spec.commonmark.org/dingus/)."
)
var body: some View {
Markdown(document)
} Alternatively, you can use an embedded DSL to describe the content of a Markdown view. Markdown {
Heading(level: 2) {
"Markdown lists"
}
OrderedList {
"One"
"Two"
"Three"
}
BulletList {
"Start a line with a star"
"Profit!"
}
} Relative URLsWhen creating a Markdown(
#"""
You can explore all the capabilities of this package in the
[companion demo project](Examples/MarkdownUIDemo).
"""#,
baseURL: URL(string: "https://github.com/gonzalezreal/MarkdownUI/raw/main/")
) Loading asset imagesA Markdown(
#"""
The Markdown view loads this image from the network:
![](https://picsum.photos/id/223/100/150)
And looks for this other image in the app's bundle:
![](asset:///puppy)
"""#
)
.setImageHandler(.assetImage(), forURLScheme: "asset") Customizing appearanceA Markdown(
#"""
## Inline code
If you have inline code blocks, wrap them in backticks: `var example = true`.
"""#
)
.markdownStyle(
MarkdownStyle(
font: .system(.body, design: .serif),
foregroundColor: .indigo,
measurements: .init(
codeFontScale: 0.8,
headingSpacing: 0.3
)
)
) Customizing link handlingBy default, a struct ContentView: View {
@State private var url: URL? = nil
@State private var showingAlert = false
var body: some View {
Markdown(
#"""
**MarkdownUI** is a library for rendering Markdown in *SwiftUI*, fully compliant with the
[CommonMark Spec](https://spec.commonmark.org/current/).
"""#
)
.onOpenMarkdownLink { url in
self.url = url
self.showingAlert = true
}
.alert(isPresented: $showingAlert) {
Alert(
title: Text("Open Link"),
message: Text(self.url?.absoluteString ?? "nil")
)
}
}
} Alternatively, if your deployment target is macOS 12.0+ or iOS 15.0+, you can customize Markdown
link handling by setting the Markdown(
#"""
**MarkdownUI** is a library for rendering Markdown in *SwiftUI*, fully compliant with the
[CommonMark Spec](https://spec.commonmark.org/current/).
"""#
)
.environment(
\.openURL,
OpenURLAction { url in
self.url = url
self.showingAlert = true
return .handled
}
) Supported Markdown ElementsMarkdownUI uses the CommonMark reference parser and fully complies with the CommonMark Spec. Below you can see a few examples of how MarkdownUI renders Markdown elements. Additionally, you can explore the full MarkdownUI capabilities in the companion demo project. Block QuotesMarkdown(
#"""
> “I sent the club a wire stating,
> **PLEASE ACCEPT MY RESIGNATION. I DON'T
> WANT TO BELONG TO ANY CLUB THAT WILL ACCEPT ME AS A MEMBER**.”
― Groucho Marx
"""#
) ListsMarkdown(
#"""
List of humorous units of measurement:
1. Systems
- FFF units
- Great Underground Empire (Zork)
- Potrzebie
1. Quantity
- Sagan
1. Length
- Altuve
- Attoparsec
- Beard-second
― From Wikipedia, the free encyclopedia
"""#
) Code BlocksMarkdown(
#"""
Use a group to collect multiple views into a single instance,
without affecting the layout of those views. After creating a
group, any modifier you apply to the group affects all of that
group’s members.
Group {
Text("SwiftUI")
Text("Combine")
Text("Swift System")
}
.font(.headline)
― From Apple Developer Documentation
"""#
) HeadingsMarkdown(
#"""
# Heading 1
A paragraph of text.
## Heading 2
A paragraph of text.
### Heading 3
A paragraph of text.
#### Heading 4
A paragraph of text.
"""#
) Thematic BreaksMarkdown(
#"""
# SwiftUI
Declare the user interface and behavior for your app
on every platform.
---
## Overview
SwiftUI provides views, controls, and layout structures
for declaring your app’s user interface.
---
― From Apple Developer Documentation
"""#
) ImagesMarkdown(
#"""
![Puppy](https://picsum.photos/id/237/200/300)
― Photo by André Spieker
"""#
) Emphasized TextMarkdown(
#"""
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/).
"""#
) InstallationYou can add MarkdownUI to an Xcode project by adding it as a package dependency.
Other Libraries |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论