在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):JohnSundell/Ink开源软件地址(OpenSource Url):https://github.com/JohnSundell/Ink开源编程语言(OpenSource Language):Swift 99.9%开源软件介绍(OpenSource Introduction):Welcome to Ink, a fast and flexible Markdown parser written in Swift. It can be used to convert Markdown-formatted strings into HTML, and also supports metadata parsing, as well as powerful customization options for fine-grained post-processing. It was built with a focus on Swift-based web development and other HTML-centered workflows. Ink is used to render all articles on swiftbysundell.com. Converting Markdown into HTMLTo get started with Ink, all you have to do is to import it, and use its import Ink
let markdown: String = ...
let parser = MarkdownParser()
let html = parser.html(from: markdown) That’s it! The resulting HTML can then be displayed as-is, or embedded into some other context — and if that’s all you need Ink for, then no more code is required. Automatic metadata parsingInk also comes with metadata support built-in, meaning that you can define key/value pairs at the top of any Markdown document, which will then be automatically parsed into a Swift dictionary. To take advantage of that feature, call the let markdown: String = ...
let parser = MarkdownParser()
let result = parser.parse(markdown)
let dateString = result.metadata["date"]
let html = result.html To define metadata values within a Markdown document, use the following syntax:
The above format is also supported by many different Markdown editors and other tools, even though it’s not part of the original Markdown spec. Powerful customizationBesides its built-in parsing rules, which aims to cover the most common features found in the various flavors of Markdown, you can also customize how Ink performs its parsing through the use of modifiers. A modifier is defined using the var parser = MarkdownParser()
let modifier = Modifier(target: .codeBlocks) { html, markdown in
return "<h3>This is a code block:</h3>" + html
}
parser.addModifier(modifier)
let markdown: String = ...
let html = parser.html(from: markdown) Modifiers are passed both the HTML that Ink generated for the given fragment, and its raw Markdown representation as well — both of which can be used to determine how each fragment should be customized. Performance built-inInk was designed to be as fast and efficient as possible, to enable hundreds of full-length Markdown articles to be parsed in a matter of seconds, while still offering a fully customizable API as well. Two key characteristics make this possible:
System requirementsTo be able to successfully use Ink, make sure that your system has Swift version 5.2 (or later) installed. If you’re using a Mac, also make sure that Please note that Ink does not officially support any form of beta software, including beta versions of Xcode and macOS, or unreleased versions of Swift. InstallationInk is distributed using the Swift Package Manager. To install it into a project, simply add it as a dependency within your let package = Package(
...
dependencies: [
.package(url: "https://github.com/johnsundell/ink.git", from: "0.1.0")
],
...
) Then import Ink wherever you’d like to use it: import Ink For more information on how to use the Swift Package Manager, check out this article, or its official documentation. Command line toolInk also ships with a simple but useful command line tool that lets you convert Markdown to HTML directly from the command line. To install it, clone the project and run
The command line tool will be installed as Calling it without arguments will start reading from
Markdown text can be piped in when
A single argument is treated as a filename, and the corresponding file will be parsed:
A Markdown string can be passed directly using the
You can of course also build your own command line tools that utilizes Ink in more advanced ways by importing it as a package. Markdown syntax supportedInk supports the following Markdown features:
Please note that, being a very young implementation, Ink does not fully support all Markdown specs, such as CommonMark. Ink definitely aims to cover as much ground as possible, and to include support for the most commonly used Markdown features, but if complete CommonMark compatibility is what you’re looking for — then you might want to check out tools like CMark. Internal architectureInk uses a highly modular rule-based internal architecture, to enable new rules and formatting options to be added without impacting the system as a whole. Each Markdown fragment is individually parsed and rendered by a type conforming to the internal To parse a part of a Markdown document, each fragment type uses a A good place to start exploring Ink’s implementation is to look at the main CreditsInk was originally written by John Sundell as part of the Publish suite of static site generation tools, which is used to build and generate Swift by Sundell. The other tools that make up the Publish suite will also be open sourced soon. The Markdown format was created by John Gruber. You can find more information about it here. Contributions and supportInk is developed completely in the open, and your contributions are more than welcome. Before you start using Ink in any of your projects, it’s highly recommended that you spend a few minutes familiarizing yourself with its documentation and internal implementation, so that you’ll be ready to tackle any issues or edge cases that you might encounter. Since this is a very young project, it’s likely to have many limitations and missing features, which is something that can really only be discovered and addressed as more people start using it. While Ink is used in production to render all of Swift by Sundell, it’s recommended that you first try it out for your specific use case, to make sure it supports the features that you need. This project does not come with GitHub Issues-based support, and users are instead encouraged to become active participants in its continued development — by fixing any bugs that they encounter, or by improving the documentation wherever it’s found to be lacking. If you wish to make a change, open a Pull Request — even if it just contains a draft of the changes you’re planning, or a test that reproduces an issue — and we can discuss it further from there. Hope you’ll enjoy using Ink! |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论